Forum Moderators: not2easy
I have the following:
#c-padding {
padding-left: 10px;
padding-right: 18px;
color: #5B5B5B;
font-size: 10pt;
font-weight: normal;
}
#c-padding a{
color: #c30;
font-weight: bold;
text-decoration: none;
}
#c-padding a:hover{
color: #999;
text-decoration: none;
}
Which works fine. But when I want to change the class of an anchor tag inside the <p> i can not get it to change. ie.
<p id="c-padding">
bla bla <a href="">bla</a> bla <a href="" class="different">bla</a> bla
</p>
why does this not work
.different a{
color: black;
}
I know the answer will be simple.
Cheers.
<p id="c-padding">
bla bla <a href="">bla</a> bla <a href="" class="different">bla</a> bla
</p>why does this not work
.different a{
color: black;
}
it's a selector thing your rule for the different <a> is actually telling the rule to apply to any <a> which has an ascendant element whose class name is
.different as opposed to seletcing an <a> with it's own class name of different which would be a.different, a.different:hover etc but what is actually in the HTML is one parent
c-padding with two different (sibling) children elements <a> #c-padding a is actually targetting both children <a>'s regardless of class names so you then need to make it more specific in order to target the second one differently #c-padding a.different
.. so this is now saying to select an <a> with it's own class name of "different" but also with a ascendant element whose id is "c-padding"
Suzy
#c-padding a {color: #c30; } has higher priority than .different {color: black; } because of the id (and the anchor isn't a descendant of an element with the class of different). You can fix the problem by calling the new style with #c-padding .different {color: black; }. Adam
<edit>sorry for redundancy, too slow</edit>