css selecting
-
ok so I have a nice bit of simple html:
<div> <h2><a href=...>A title</a><h2> <div>Now I want to have a bottom border over the whole h2 and when the link (the
<a>) is hovered I want the border colour to change.CSS:
h2{ border-bottom:1px #eee solid; } h2 a:hover ???{ border-color:blue; }What goes where the ??? is? If I leave it as is it will set the border colour of the
<a>when I actually want the border colour of the<h2>to be set.So my selector should say: when the
<a>, that is inside/the child of an<h2>is hovered, set the css properties for the<h2>I what to have the border-bottom set to the
<h2>rather than the<a>for these reasons:
– the<a>is an inline element so the border will only extend as long as the text, whereas the<h2>is a block element so automatically takes up the entire width.
– The rule will also be applied to<h2>s that are not links, and I don’t what the border colour to change on hover when the h2 is not a link.
The topic ‘css selecting’ is closed to new replies.