Reputation: 7009
How can I define the style attribute values for a group of child elements from the parent element's style.
I want to achieve the following-
<div style="style for the child <span> tags">
<span>a</span>
<div>b</div>
<span>c</span>
<div>d</div>
</div>
Say I want to set the color of the text only in the child <span>
tags but not for the text in the child <div>
tags. Here I want to know how to do it in case of both inline and internal CSS.
How can I do it?
Upvotes: 1
Views: 946
Reputation: 179
you can give class to parent div and then access its child node like this in css tag..
.fooClass span{color:red;}
Upvotes: 0
Reputation: 580
One way is like this
div span {
/* styles */
}
or if you need to be more specific to the top level div put an id on it and then target that like this
#top_level_div span {
/* styles */
}
Upvotes: 0
Reputation: 37701
You can't do it inline.
Give your main div an id, let's use container
. The css would be like this:
div#container span {
styles for the spans inside the main div
}
Of course, if you have more than one such container div, use class instead of id. The approach is the same.
Upvotes: 3