Forum Moderators: not2easy

Message Too Old, No Replies

Anchor class inside a <P>

a different anchor class in a p - should be simple

         

Aberdeen

7:34 am on May 26, 2004 (gmt 0)

10+ Year Member



I thought i knew a bit about css, I have even designed my whole site in css, and so I was a bit perplexed when I could not do this simple thing.

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.

SuzyUK

8:04 am on May 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Aberdeen

<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

aeve

8:11 am on May 26, 2004 (gmt 0)

10+ Year Member



#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>