Jump to content

CSS Selectors


shadowayex
 Share

Recommended Posts

Hello,I'm trying to create a stylesheet for a MySpace, which is not going well. Not all of the things I want to affect with CSS have classes or IDs, so I was wondering if there was a way to try to use basic selectors to get things like the 4th table inside of the body tag, and stuff like that. Pretty much like in JavaScript, you can do it with body.getElementsByTagName("table")[4];, which would work if I could use JavaScript. But since MySpace won't allow that, I was wondering if CSS had the same capability?

Link to comment
Share on other sites

Tricky. If IE didn't matter (again) we could use some CSS3 selectors like :nth-child or :nth-of-type, which would do just what you want. If you really, really want the 4th table, and they are not nested, then this might work. Not sure, haven't tried it:table ~ table ~ table ~ table { etc.Note that this will also catch every table after the 4th also. :)Are you sure that 4th table has no distinguishing attributes in its tag apart from name or id (like a unique width or something)? Attribute selectors work very well.

Edited by Deirdre's Dad
Link to comment
Share on other sites

Tricky. If IE didn't matter (again) we could use some CSS3 selectors like :nth-child or :nth-of-type, which would do just what you want. If you really, really want the 4th table, and they are not nested, then this might work. Not sure, haven't tried it:table ~ table ~ table ~ table { etc.Note that this will also catch every table after the 4th also. :)Are you sure that 4th table has no distinguishing attributes in its tag apart from name or id? Attribute selectors work very well.
Well, since it's MySpace, they use really bad HTML, the table I'm looking at in particular opens like so:<table border="0" cellspacing="0" cellpadding="0" width="300" height="100">Which, I was going to just use attribute selectors, but I didn't know if changing the height or width would ruin it if I used those as attributes (I was going to test for this). CSS3 Selectors would be wonderful. I looked at them a while back and, well, I considered buying an engagement ring for them. But, as you said, IE. I'll play around with attribute selectors and see if I can get to job done that way. If not, well, I can at least make it pretty for everyone not using IE :)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...