Looking for a CSS selector.

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Looking for a CSS selector.

Post by JellyFish »

I have a image wraped around an ancor and I need a way to select the ancor not the img. Ids, names and classes aren't exceptable.

How would I do this with CSS?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Unless something has changed, images aren't containers. Maybe you mean you have an image inside an anchor?

Code: Select all

a img
{
  border-left: 2px orange;
}
User avatar
JellyFish
DevNet Resident
Posts: 1361
Joined: Tue Feb 14, 2006 7:18 pm
Location: San Diego, CA

Post by JellyFish »

I do have an image inside an anchor. But I want to select the anchor not the image. So doing:

Code: Select all

a img {

}
would select the image element and all the code within the brackets only effect the img, not the anchor, if I'm correct. I want to select the anchor. So is there a parent selector of some-kind in css?

I can't simply do:

Code: Select all

a {

}
'Cause that would select EVERY anchor. Nether could I use class or ID selectors, it's just not an option (Don't ask why).
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Post by matthijs »

Using

Code: Select all

a { }
is really the only way. As far as I know, there is no "parent"-selector in css (or it's in the css4 specs somewere ;) ). Then to target some other a elements, you have to have some class, id or use a descendant selector to target them.

Is there really no way to separate these links from the others?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

JellyFish wrote:I can't simply do:

Code: Select all

a {

}
'Cause that would select EVERY anchor. Nether could I use class or ID selectors, it's just not an option (Don't ask why).
The only ways to select an individual element are through either a class or an ID*. If those aren't options then you're stuffed.

Could you wrap the anchor in another element like a span, and give that an ID?

* Technically you could traverse the DOM tree and pick the 10th anchor on the page, and change it's style with JS, but that would be horrible and rubbish.
Post Reply