Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Li item on two lines. Second line has no margin

I'm currently working on an unordered list containing list items with taglines. I'm having a problem concerning one list item, which is long enough to take up two lines (See image)

enter image description here

I want it so that the second line is aligned with the first line. This is the HTML code i'm using. I used fontAwesome for the check images.

ul {    width: 300px;  }
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"/>  <ul class="fa-ul custom-list">    <li><i class="fa fa-check fa-fw"></i>List item on 1 line</li>    <li><i class="fa fa-check fa-fw"></i>List item on 1 line</li>    <li><i class="fa fa-check fa-fw"></i>This is a list item that actually takes up 2 lines. Looks ugly</li>  </ul>

I already tried to enter multiple &nbsp; in between '2' and 'lines' but that seems like a really bad practice to me. I hope someone can help me with this problem.

like image 883
Kevin Groen Avatar asked Oct 27 '15 08:10

Kevin Groen


People also ask

How do you indent the second line of a paragraph in CSS?

Output: Method 2: By making the position relative to the first line, set the text-indent to -26px and padding-left value to 26px. Here in this example, we have made the position of the second line relative to the first line. So the second line is indented/aligned according to the first line.

How do you indent Li in CSS?

You can use the CSS text-indent property to indent text in any block container, including divs, headings, asides, articles, blockquotes, and list elements. Say you want to indent all div elements containing text on a page to the right by 50px. Then, using the CSS type selector div, set the text-indent property to 50px.


1 Answers

This is because the tick is inline content so when the text wraps it will continue to flow as usual.

You can stop this behaviour by taking advantage of text-indent:

The text-indent property specifies how much horizontal space should be left before the beginning of the first line of the text content of an element.

text-indent (https://developer.mozilla.org/en-US/docs/Web/CSS/text-indent)

By supplying a negative text-indent you can tell the first line to shift a desired amount to the left. If you then specify a positive padding-left you can cancel this offset out.

In the following example a value of 1.28571429em is used because it is the width set on the .fa-fw by font-awesome.

ul {    width: 300px;  }  li {      padding-left: 1.28571429em;      text-indent: -1.28571429em;  }
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css" rel="stylesheet"/>  <ul class="fa-ul custom-list">      <li><i class="fa fa-check fa-fw"></i>List item on 1 line</li>      <li><i class="fa fa-check fa-fw"></i>List item on 1 line</li>      <li><i class="fa fa-check fa-fw"></i>This is a list item that actually takes up 2 lines. Looks ugly</li>  </ul>
like image 72
Hidden Hobbes Avatar answered Oct 17 '22 11:10

Hidden Hobbes