Formatting an indented list in CSS

Posted by Colen on Stack Overflow See other posts from Stack Overflow or by Colen
Published on 2010-06-16T00:03:05Z Indexed on 2010/06/16 0:12 UTC
Read the original article Hit count: 577

Filed under:
|

Hi,

Let's say I have a list, with an arbitrary number of indentation levels, like so:

Item
  Item
    Item
Item
  Item
Item
  Item
  Item
    Item
      Item
        Item

If I'm displaying this list in an HTML document, how can I use CSS to handle the indentation? There might be an arbitrary number of indentation levels (although in practice there isn't going to be more than 5 or so).

I don't want to create an "indent1" class that indents 10 pixels, an "indent2" class that indents 20 pixels, etc - that's clumsy. Is it possible to create a general rule that will indent by a certain distance based on an attribute value, or the position of an element in the hierarchy?

© Stack Overflow or respective owner

Related posts about css

Related posts about html5