css attribute selectors
- Started
- Last post
- 17 Responses
- jbenjohnson
Does anybody know of a list of all the possible attribute selectors that can be used? I know the basics like href, title, class, etc. But I want to know all my options.
cheers
- acescence0
any valid attribute of a tag can be used as an attribute selector. note that attribute selectors can be strange in IE, and don't work below 7
- jbenjohnson0
what about targeting a URL?
- jbenjohnson0
for example, i want to auto-select a navigation item. can I do that via an attribute selector? (I can't touch the html).
- acescence0
what do you mean by auto-select a nav item? change it's styling based on the url it points to?
this may help you...
- jbenjohnson0
yes. i'll check the link - i think it gave me an idea. thx
- neverblink0
this is actually pretty easy to do with jQuery, although when changing the css with JQ, it will take effect after the page has loaded.
$("a [href='mylink.html']").css()
or addClass() or whatever you want to do with it
- Stugoo0
you can use any attribute to select any element in any (modern) browser (other than ie6). or you can use javascript (as mentioned above).
the you can find the attributes supported for each element here :
http://www.google.com/url?sa=t&a…
(pdf)- sorry that should be
in any (modern) browser using CSSStugoo
- sorry that should be
- jbenjohnson0
good list stugoo. thx.
I'd love to use javascript, but I can't add anything to the HTML, I can only modify the CSS.
So i was thinking, if there was a way with an attribute selector i could say - when you're on a page that has "red" in the URL, the Red navigation item would be auto-selected.
Make sense?
again, I could easily accomplish this via html and js, but i don't have that option
- Stugoo0
got some sample html? not sure what you are asking for
- Stugoo0
I don't think that you can add an 'active state' to the page without adding a class to the html.... let me see what you got...
- jbenjohnson0
i don't really have anything at this point. the nav is in a UL and I'm trying to figure out the CSS.
<ul>
<li><a href="#">Red</a></li>
<li><a href="#">Black</a></li>
</ul>
- acescence0
like this...?
- TheBlueOne0
add an ID to the body tag and style from there, no?
- Oh..nevermind...just read you can't edit the htmlTheBlueOne
- jbenjohnson0
acescence - that's what i started with, but its not dynamic, it always makes that link red... am i reading that right?
- acescence0
it makes any link with the word "red" in the href red, is that not what you want?