CSS First Child Selectors
- Started
- Last post
- 26 Responses
- ethios
Hey guys,
I have a load of tables inside a div, some are nested inside each other, how can I set a style in CSS that OLY applies to the top level tables? Not the tables inside the tables? If you get me, currently I have a working version of this in Firefox using this:
div.class > table
But it doesn't work in IE?
Any help is appreciated!
- UndoUndo0
put a class reference inside yr table tag
- ethios0
What if this is not possible? (It's not without a LOT of work)
- versa0
maybe i misunderstand, but why not just create a general class that goes on tables and alleviate the need to use the child selector
traverse ?
- ethios0
As I said ^^
- MX_OnD0
I'm slowly getting tired of repeating myself....
DON'T MIX TABLES AND DIVS!!!
- sparker0
i agree with MX. and, fixing the markup to work properly via css is going to cause hours of headaches.
there isn't an easy way to do it. at least not a cross browser way.
the tables should have been tagged with class or id attributes in the planning stage.
why did you mix specs like that?
- Dancer0
What MX said, learn the way of the CSS and you also will be strong young padowan.
On a side note only use tables if you are displaying tabular info.
- ethios0
Why the hell does everyone have such a problem with tables? Do you layout a sales report using divs? No. They still serve a valid function in web design
- ethios0
Exactly
- sparker0
ie doesn't support the :first-child pseudo class to my knowledge.
- instantok0
all that has been said before i agree with...you could maybe give this a shot...it's going to get messy though
div table { your styles }
div table table { other styles }
- sparker0
no they don't. read the specs. tables are for tabular data. NOT FOR LAYOUT.
christ.
- sparker0
that will style all tables and also confuse css rendering.
child selectors are the proper way but they're not supported in ie.
- MX_OnD0
the "C" in CSS is for cascading thus meaning that all children of a praticular object inherit properties....
hence the necessity to define all children with a child selector OR give them their own IDs.. (verbose and messy)
Tables ONLY for Tabular data.
end of lesson.
- ethios0
Yes thats what I said in my post up there
- sparker0
but gratuitous nesting of tables is bad.
gratuitous nesting of any html element can be problematic.
there are attributes and elements in markup that allow for such layouts semantically.
simply, there is a right way and a wrong way. the wrong way "might work" sometimes...but cause headaches none the less.
- gabriel20
are you able to use javascript on this document? if so, I would just use that to select the top level table and apply the class directly to it via javascript. that would avoid having to go in and modify the html itself
- heavyt0
i would first apply a rule to all tables or cells
.class td{
rules
}
then, undo the nested tables or cells
.class td td{
undo those rules
}TR1
- spiralstarez0
Didn't you post this exact same thing last week?
Just post your damn markup and I'll tell you if it's possible, even show you the exact code.