Forum Moderators: not2easy

Message Too Old, No Replies

Help : use multiple selector to override anchor style

         

jaysaiom

1:29 am on Jul 20, 2008 (gmt 0)

10+ Year Member



Hi,

I have container div that has two classes h01 and h02. It encapsulates anchor link. I want to have the anchor link within this div show in different color compared to other anchor links in the html.

How can i say that the anchor link within this specific div will be shown in red color. My approach is as shown below but does not work as expected. I would appreciate any help in knowing what is wrong here?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml"><HEAD><TITLE>test css</TITLE>
<STYLE type=text/css>
.h01 {
FONT-WEIGHT: bold
}
.h02{
FONT-WEIGHT: bold
}
.h01 .h02 A{
COLOR: red;
}
.b01 .c01 A {
COLOR: black
}
.b01 .c01 .link A {
COLOR: black
}
</STYLE>

</HEAD>
<BODY>
<DIV class="h01 h02"><A href="example.com/net/org">Test Heading</A></DIV>
</BODY></HTML>

lavazza

2:09 am on Jul 20, 2008 (gmt 0)

10+ Year Member



instead of
.h01 .h02 A{
COLOR: red;
}

try
.h01 A, .h02 A{
COLOR: red;
}

lavazza

2:29 am on Jul 20, 2008 (gmt 0)

10+ Year Member



One other (unrelated?) issue:

I guess what's above is just a trimmed down, testing version, but...to my eye, the xmls namespace declaration looks odd (wrong?) with a 4.01 Transitional loose doctype

Instead of
<HTML xmlns="http://www.w3.org/1999/xhtml">

I have a hunch a plain old
<HTML>
tag would be more standards compliant
or maybe
<html lang="en-GB">
or
<html lang="en-US">

and a charset declaration wouldn't hurt, either
e.g.
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

That way, you could use the w3c html and css validators to identify bugs

:)

jaysaiom

5:30 pm on Jul 20, 2008 (gmt 0)

10+ Year Member



Appreciate the quick response, Lavazza. This forum is very vibrant.

I would like the anchor link to be red only if container div uses both styles h01 and h02. There are other divs (not in example) that use either h01 and h02 for which i do not want the anchor to be red.

You are correct about the namespace declaration. It got trimmed down while i was trimming down the example. I will update that.

Thanks,
Jay

SuzyUK

7:36 pm on Jul 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



.h01 .h02 A{
COLOR: red;
}

if that's your unique(ness) then you need to miss out the space. You need some way to target using existing class/id names without the parent>child relationships.. CSS can do that (if you thought it, then so did they)

in order to select an element whch has multi class or ID names then you need to concatenate them

.h01.h02 a{
color: red;
}

unfortunately you may be just a little bit ahead of your time :( IE6 when presented with a multi class target will only read the last class in the selector so therefore all the hard work may mean nothing

but you're right it can be done.. IE7 gets it right which is why this selector has even "got here" :)

[edited by: SuzyUK at 7:39 pm (utc) on July 20, 2008]

jaysaiom

9:46 pm on Jul 20, 2008 (gmt 0)

10+ Year Member



Thanks SuzyUK. You rock!
Specifying the class name without space did the trick. I will put some workaround for IE 6 users. Thanks for pointing that out.