Hello
I have a page layout that has an image wrapped in a link. Then below that is a simple text link.
I have set the css to add an arrow after the text link. But this is also applying to the img link. This content is added via a CMS and I’d like to avoid having to put a special class on the image to remove the arrow.
I’ve tried a few things to remove the arrow but can’t get it to work. Can anyone help?
Without adding a new class, the best you could probably do with CSS is to hide the arrow by shifting the img on top of it.
You would need to make sure it layers above the arrow by adding position:relative; to create a stacking context.
Something like this -
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Test Page</title>
<style type="text/css">
div {
width:60%;
margin:0 auto;
background:#EEF;
}
a:after {content: " \\2192";}
[COLOR=#0000ff]a img {
position:relative;
margin-right:-1.3em;
vertical-align:text-bottom;/*hide any text-decoration*/
}[/COLOR]
</style>
</head>
<body>
<div>
<p>Some random text with a <a href="#">link</a> in it.</p>
<p>String of text with an image
<a href="#">
<img src="http://www.css-lab.com/demos/vertical-center/images/image-35.gif" alt=""/>
</a> nested in an anchor.
</p>
<p>Some random text with a <a href="#">link</a> in it.</p>
</div>
</body>
</html>
Hey Rayzur, thanks so much.
This does work, but unfortunately because I have text floated to the right of the image, it slides accross and is covered by the image when the negative margin is applied. So not sure I can use it.
My image does actually have a unique class. I tried to work it into the css to cancel out the :after content but couldn’t get it to work.
I tried:
This does work, but unfortunately because I have text floated to the right of the image…
I was wondering about that, must be some sort of image caption text.
Can you give a link to the page or an example of the content that is nested in the anchor with the img?
My image does actually have a unique class. I tried to work it into the css to cancel out the :after content
As you know, the problem is not really the img. It’s the :after content applied to the anchor. CSS does not allow you to climb backwards up the dom like that. In other words, you can’tstyle the parent from the child, but you canstyle the child from the parent.
You can’t add the pseudo :after to an img element as it is what is known as an “empty” element. It self closes and it cannot contain any content.
EDIT:
It really sounds like you need to add a class to the anchors that have images nested in them or rely on javascript to climb backwards through the dom.