CSS: Can I use the classes of nested elements to narrow css down?
Here is an example of what I have:
<div class="node node-blog">
<div class="field-item even">
<img src="image.png"/>
</div>
</div>
What I would like to do is apply a style to the img element only when inside the node-blog and field-item divs, but this does not work:
.node-blog .field-item img {float:right开发者_如何学JAVA;}
Sure I am doing something wrong.
Thanks.
Provided style's fine
Unless you have other errors in your CSS file, this line seems correct. It's most probably something very stupid. Maybe some typo in your actual code if you haven't actually copy-pasted it here...
As long as your img
is contained within a subtree of .field-item
that is in a subtree of .node-blog
this should work. You don't have to provide the whole path.
Other rule overrides yours
Unless you have a different rule on img
that sets float to it. CSS style of it
- Must be more specific to the one provided to override yours.
- Is less specific but sets float setting as
!important
.
you could try:
.node-blog .field-item img {float:right!important;}
...another rule may be more selective
All else being equal, it should work. The problem is in a piece of code you aren't sharing with us.
精彩评论