chicane
chicane

Reputation: 2081

CSS anchor style for images

i set up a style for all my links but the problem is that any anchor that has an image obviously will have the same style.

is there any way i can overwrite the style for the images without having to apply a class to all the images that removes that style?

Upvotes: 1

Views: 7221

Answers (4)

Scott Hanselman
Scott Hanselman

Reputation: 17692

You can use jQuery qualified selectors $('a:has(img)')

Upvotes: 1

Jacob Nelson
Jacob Nelson

Reputation: 3006

I would recomend rewriting your code to not use images but for your links with images just use clickable divs displayed as blocks.

<div id="x"><a href=".." class="y"></a></div>


.y {
display: block;
}

#x {
width:..;
height:..;
padding:0;
margin:0;
background-image:url(IMGPATHHERE!);
}

#x:hover {
width:..;
height:..;
padding:0;
margin:0;
background-image:url(THEHOVERIMGHERE!);
cursor:hand;
}

Upvotes: 3

Ken Browning
Ken Browning

Reputation: 29091

No, there is no CSS selector which will capture <a> elements which contain only an <img> element. You will need to apply a class either at design-time or at run-time with javascript.

Upvotes: 1

Richard Sim&#245;es
Richard Sim&#245;es

Reputation: 12791

a img {
 /* alternative style for hyperlinked images */
}

Upvotes: 3

Related Questions