Indent Starting from The Second Line of a Paragraph with CSS

Indent starting from the second line of a paragraph with CSS

Is it literally just the second line you want to indent, or is it from the second line (ie. a hanging indent)?

If it is the latter, something along the lines of this JSFiddle would be appropriate.

    div {
padding-left: 1.5em;
text-indent:-1.5em;
}

span {
padding-left: 1.5em;
text-indent:-1.5em;
}
<div>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</div>

<span>Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.</span>

Indent 2nd line of a paragraph to line up with first line?

Pad the entire paragraph to the right and then pull the fontawesome icon to the left to fill the space created.

.result {
padding-left: 30px;
}

.result .location:before {
content: "\f041";
color:#b3b3b3;
margin-left: -10px;
padding-right: 2px;
}

jsfiddle

Text indent starting from 2nd paragraph

You could do it by applying the text-indent to all p tags, and removing it on the first-child:

p{text-indent: 20px}p:first-child{text-indent:0}
<p>First</p><p>Second</p><p>Third</p>

How to keep indent for second line in ordered lists via CSS?

Update

This answer is outdated. You can do this a lot more simply, as pointed out in another answer below:

ul {
list-style-position: outside;
}

See https://www.w3schools.com/cssref/pr_list-style-position.asp

Original Answer

I'm surprised to see this hasn't been solved yet. You can make use of the browser's table layout algorithm (without using tables) like this:

ol {
counter-reset: foo;
display: table;
}

ol > li {
counter-increment: foo;
display: table-row;
}

ol > li::before {
content: counter(foo) ".";
display: table-cell; /* aha! */
text-align: right;
}

Demo: http://jsfiddle.net/4rnNK/1/

Sample Image

To make it work in IE8, use the legacy :before notation with one colon.

Get second line of bullet item to indent as first part - not underneath the bullet?

My take on this would be to include the bullet in another div and then wrap both divs in a container div.

.row2 {    padding-left: 20px;    overflow: hidden;    max-width: 500px; }.red-square-5 {    position:absolute;    width:5px;    height:5px;    margin-top: 0.5em;    background:#f00; }
<div class="container-div">    <div class="red-square-5"></div>    <div class="row2">        Long long long long long long long long long long long         long long long long long long long long long long long         long long long title    </div></div>

Text indent after the first line in a paragraph

You need text-indent. Normally text-indent pushes the first line inwards, but if you give it a minus figure and use a positive margin, you can achieve the effect you're after.

text-indent: -10px;
margin-left: 10px

CSS second-line indent not working

If the element is inline it will indent the first line, otherwise if it's a block element it will indent the rest of the lines, which is just like Briguy37 said, since that's the difference between DIV and SPAN.
I just wanted to clear out that it's not a "problem with span".

Indent first line of a paragraph, but only if it takes multiple lines

Here is hacky idea that requires an extra wrapper:

p {
max-width: 350px;
line-height:1.2em; /* height of one line */
}
.e {
display:flex; /* a flex container to be able to use 100% in the height*/
}
/* a pseudo element to create the indentation*/
.e p:before {
content:"";
float:left;
width:20px;
/* 0px if 100% (height of p) is less or equal to 1.2em (one line)
1px if 100% is bigger than one line
*/
height:clamp(0px,100% - 1.2em,1px)
}
<div class="e"><p>This is a pretty long paragraph which spans over a few lines. For that reason I wish its first line to be indented (as it should be).</p></div>

<div class="e"><p>These are short paragraphs.</p></div>

<div class="e"><p>I don't want them indented.</p></div>

<div class="e"><p>Unless they take multiple lines.</p></div>


Related Topics



Leave a reply



Submit