what is the proper styling convention?

R

richard

<div class="one">
<div class="item">data</div>
</div>
<div class="two">
<div class="item">data</div>
</div>

In this example I want to have "item" showing as one color in "one".
Then in "two"showing as another color.
How is this done properly?
 
B

Ben Bacarisse

richard said:
<div class="one">
<div class="item">data</div>
</div>
<div class="two">
<div class="item">data</div>
</div>

In this example I want to have "item" showing as one color in "one".
Then in "two"showing as another color.
How is this done properly?

The trouble with examples is that it's hard to determine what the
general rule is. To apply a style to all elements with class "item" that
are descendents of an element with class "two", you'd write

.two .item { ... }

(and analogously for class "one"). But all of these selectors work as
well:

.two div
.two > .item
div.two .item
.two div:first-child

and so on and so on. The "best" solution depends on exactly what the
divs represent.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top