Help with CSS Cascade (or maybe it is inheritance?)
Posted: 08 April 2009 11:35 AM   [ Ignore ]
Newbie
Rank
Total Posts:  2
Joined  2009-04-08

I have a tag selector defined for all my heading elements (h1-h4) that I use site wide. I was simply trying to create a “highlight” for urgent messages by creating a class called “alerts” that would do some table and heading changes. I found I could not get this to work with what I understood to be a compound selector like this:

.alerts h3 {
  color
#F00;

When I did that, the normal h3 selector in the CSS file took precedence.

When I coded it like this, it worked:

h3.alerts {
   color
#F00;

Basically the HTML applies class=“alerts” to the tag.

I’ve read up on what should take precedence and can’t figure out why the other one works. I’d prefer to use the first style, as there are a number of different tags I want the “alerts class” to affect.

What I am missing?

Thanks!

Profile
 
 
Posted: 09 April 2009 04:46 AM   [ Ignore ]   [ # 1 ]
Newbie
Rank
Total Posts:  9
Joined  2009-04-09

I’ve read up on what should take precedence and can’t figure out why the other one works. I’d prefer to use the first style, as there are a number of different tags I want the “alerts class” to affect.

Hi,
All you need to do is just set the class only and then apply that class to any element in the html.

.alerts {
  color
#F00;

Then in the html as you probably already know it will look like this.

<h3 class"alerts">Highlighted Heading</h3
Profile
 
 
Posted: 09 April 2009 10:35 AM   [ Ignore ]   [ # 2 ]
Newbie
Rank
Total Posts:  2
Joined  2009-04-08

Yes thanks, I knew that would work. The reason I want to be more specific is like this:

Say in this alert section, I have a table of news. I want the

<th
and
<td
centered, along with a bunch of other styling. I am surely not going to put a class= on every data element, too messy. So what I was hoping for was to put the class on the
<table

element and then use:

.alerts {
 put all generic styling 
for tables herelike colorbackbrong
}
.alerts td,th {things for table data}
.alterts h1,h2,h3 {stuff for headings} 

Anyway, perhaps the book I read showed invalid syntax. I’ve got a fair amount of CSS on the site for navigation, etc. and all working well. I must just be having a brain f*rt on how to do this easily.

Profile
 
 
Posted: 09 April 2009 01:55 PM   [ Ignore ]   [ # 3 ]
Newbie
Rank
Total Posts:  9
Joined  2009-04-09

Ah, yes I see what you are wanting to do. See if this reference on Selector Grouping will help you out. Be sure to click on the “Play” tab for a live example that you can edit and preview.

Profile