2

Is it possible to style an unordered list so that the second line and the ones after that are indented the same as the first line of the list item?

Please see the example for exactly what I mean

O----First Line
     --SECOND LINE SHOULD START HERE
     --EVERY OTHER LINE SHOULD BE LIKE THIS ALSO
3
  • 5
    You can nest a ul inside of another ul to get what you want. Commented Jul 31, 2014 at 18:19
  • When you mention those indented lines past the first, are those sub-bullets or are they wrapped lines of text? Commented Jul 31, 2014 at 18:40
  • W3 wiki - Nested lists in HTML Commented Jul 31, 2014 at 18:48

5 Answers 5

2

Just to supplement my comment, here is a jsfiddle demonstrating what I mentioned. http://jsfiddle.net/R5ptL/

<ul>
   <li>Parent</li>
   <ul>
       <li>Child1</li>
       <li>Child2</li>
       <li>Child3</li>
   </ul>
   <li>Parent2</li>
</ul>

And if you want them to be the same style...

ul, li {
    list-style-type: circle; /* or whatever style you choose */
}

EDIT: How to do this with multiple unordered lists AND CSS only: http://jsfiddle.net/R5ptL/1/

Sign up to request clarification or add additional context in comments.

7 Comments

This is not what the OP asked. He specifically wanted the multiple lines within a single list item to have indentation on every line after the first one.
@Jason - That is one way to interpret the question. Semantically, a nested list like this would be more suitable if the first item is a parent of the subsequent items.
@Jason The OP did not state he only wanted there to be one list. Is looks like he is building a heirarchy and this is the correct way to do so.
@gwin003 - The parent closing </li> should wrap around its child <ul>
@misterManSam Hm, I've never done it that way. Checking with my fiddle, it actually produces the same result both ways.
|
0

use the css first-child selector to apply the indent to every line other than the first. ex:

ul li:first-child{margin:0px;}
ul li{margin:5px;}

Comments

0
li:not(first-child) {
  margin-left: 20px;
}

or

li {
  margin-left: 20px;
}
li:first-child {
  margin-left: 0;
}

1 Comment

Couple things: There's no explanation here as to why this would work, it's just code. Second, while it would work, it's dependent on knowing the exact width that the indent is. It would probably be better to embed a second level of ul li to move the sub items over automatically.
0

It's like this: (HTML solution, not CSS)

<ul>
<li> first item </li>
<li> second item
<ul>
<li>first item of second list</li>
<li>second</li>
</ul>
</li>
<li> continue primary list </li>
</ul>

In short, you nest a complete new UL inside the primary UL.

Comments

0

My first answer was apparently incorrect after further testing. This should work though:

ul li {
    text-indent:-10px;
    margin-left:10px;
}

NOTE: This answer runs under the assumption that every line other than the first is simply wrapped text. If those other lines are meant to be sub-points, go with gwin003's answer.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.