Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Indents in nested lists in HTML / CSS

Tags:

html

css

I've started using Twitter Bootstrap, which is useful for me (as a programmer) to get a decent looking site without having to write much CSS.

However something is driving me crazy. I have a nested list like

<ul>
  <li>Hello</li>
  <li>World 
    <ul>
      <li>Wide</li>
      <li>Web</li>
    </ul>
  </li>
</ul>

But the first and second level of this list are NOT getting indented differently (ie. they align with each other on the left)

In normal html nested lists, deeper sublists indent more. But something in the style sheet must be turning this off. How do I find what controls this? I can't see a CSS "list indent" attribute for li elements in any documentation.

like image 906
interstar Avatar asked Feb 27 '12 22:02

interstar


People also ask

How do you indent a nested element in HTML?

Many developers choose to use 4-space or 2-space indentation. In HTML, each nested tag should be indented exactly once inside of its parent tag. Place a line break after every block element. Do not place more than one block element on the same line.

How do you indent a list 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.

What is a nested indent?

In typography, a form of indention in which each subsequent indent is set relative to the previous indent, rather than from the left (or right) margin.

How do I remove the indent from a list in CSS?

The padding-left:0 is used to remove indentation (space) from left. The list-style: none property is used to remove list-style property from the list of items.


1 Answers

Just use Firebug in FF or Chrome dev-tools: right-click on your target and select inspect element. You can visually and textually inspect the CSS properties to see what's causing the collapse.

You probably want a rule like

ul > li {
    margin-left: 10px;
}
like image 175
calebds Avatar answered Sep 18 '22 14:09

calebds