Which has priority?

  • Thread starter Paul F. Johnson
  • Start date
P

Paul F. Johnson

Hi,

I have a color attribute set in the body part of my style sheet. This
style sheet is included in the HTML file by the usual

<link href="css/dp.css" rel="stylesheet" type="text/css" />

For some reason, I need some specific pages to use a different text color
for the entire body, I therefore have the following line

<body bgcolor="black" color="#00ffcc" onload="init()">

(The JS is a bog standard NS4 hack to resize the viewing window - it can
be safely ignored)

The color though remains the same as the one defined in the style sheet.

Shouldn't the color defined in the body element of the HTML take priority over
that of the stylesheet?

TTFN

Paul
 
M

Matthias Gutfeldt

Paul said:
Hi,

I have a color attribute set in the body part of my style sheet. This
style sheet is included in the HTML file by the usual

<link href="css/dp.css" rel="stylesheet" type="text/css" />

For some reason, I need some specific pages to use a different text color
for the entire body, I therefore have the following line

<body bgcolor="black" color="#00ffcc" onload="init()">

(The JS is a bog standard NS4 hack to resize the viewing window - it can
be safely ignored)

The color though remains the same as the one defined in the style sheet.

Shouldn't the color defined in the body element of the HTML take priority over
that of the stylesheet?

Obviously not :). Check out the cascading rules:
<http://www.w3.org/TR/CSS2/cascade.html#cascade>

"6.4.4 Precedence of non-CSS presentational hints
The UA may choose to honor presentational hints from other sources than
style sheets, for example the FONT element or the "align" attribute in
HTML. If so, the non-CSS presentational hints must be translated to the
corresponding CSS rules with specificity equal to zero. The rules are
assumed to be at the start of the author style sheet and may be
overridden by subsequent style sheet rules. "


So what you need to do is create a second style rule. For example, you
could use an id selector for those 'specific' pages in your stylesheet:

body {your usual styles}
body#specificpage {background-color:black; color:#00ffcc;}

<body id="specificpage">



Matthias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,091
Messages
2,570,604
Members
47,224
Latest member
Gwen068088

Latest Threads

Top