Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I/can I recursively indent div's with a class?

Tags:

html

css

I'm looking at a page of html code that follows this pattern:

<div id='1' class='someclass'>
  contents
  <div id='2' class='someclass'>
    other contents
    <div id='3' class='someclass'>
      yet even more contents
    </div>
  </div>
</div>

I'm looking to indent the contents of the inner divs, without changing their class, such that the page will be displayed so:

contents
  other contents
    yet even more contents

Is this feasible through manipulation of 'someclass'? If so, how?

Note that the divs may contain some other, fairly simple html - such as headings, lists, etc...

like image 994
blueberryfields Avatar asked Jul 09 '13 23:07

blueberryfields


2 Answers

I think your looking for the following css rule

.someclass { margin-left: 10px; }

For no indent on the first item

.someclass .someclass { margin-left: 10px; }
like image 69
bryjohns Avatar answered Nov 14 '22 16:11

bryjohns


I'm not really sure if this is what you're after, but you can do the following:

(sidenote: you should avoid starting a id or class with a number for crossbrowser compatibility)

div#div1 div {
  margin-left:20px;
}

This will display and indent of 20px on all the div's inside the parent div with id div1.

See this fiddle.

like image 1
Jeroen W Avatar answered Nov 14 '22 15:11

Jeroen W