Skip to content Skip to sidebar Skip to footer

Indent List In Html And Css

I'm new to CSS and working with list. I tried using one of the code I saw on w3schools which shows how to indent lists:

A nested List:

Solution 1:

Yes, simply use something like:

ul {
  padding-left: 10px;
}

And it will bump each successive ul by 10 pixels.

Working jsFiddle

Solution 2:

It sounds like some of your styles are being reset.

By default in most browsers, uls and ols have margin and padding added to them.

You can override this (and many do) by adding a line to your css like so

ul, ol {  //THERE MAY BE OTHER ELEMENTS IN THE LIST
    margin:0;
    padding:0;
}

In this case, you would remove the element from this list or add a margin/padding back, like so

ul{
    margin:1em;
}

Example: http://jsfiddle.net/jasongennaro/vbMbQ/1/

Solution 3:

I solved the same problem by adding text-indent to the nested list.

<h4>A nested List:</h4><ul><li>Coffee</li><li>Tea
    <ulid="list2"><li>Black tea</li><li>Green tea</li></ul></li><li>Milk</li></ul>

#list2
{
 text-indent:50px;
}

Solution 4:

You can use [Adjacent sibling combinators] as described in the W3 CSS Selectors Recommendation1 So you can use a + sign (or even a ~ tilde) apply a padding to the nested ul tag, as you described in your question and you'll get the result you need. I also think what you want it to override the main css, locally. You can do this:

<style>li+ul {padding-left: 20px;}
</style>

This way the inner ul will be nested including the bullets of the li elements. I wish this was helpful! =)

Solution 5:

You can also use html to override the css locally. I was having a similar issue and this worked for me:

<html><body><h4>A nested List:</h4><ulstyle="PADDING-LEFT: 12px"><li>Coffee</li><li>Tea
    <ul><li>Black tea</li><li>Green tea</li></ul></li><li>Milk</li></ul></body></html>

Post a Comment for "Indent List In Html And Css"