views:

627

answers:

4

I'm re-asking this question because its answers didn't work in my case.

In my stylesheet for printed media I want to append the url after every link using the :after pseudo-class.

a:after {
    content: " <" attr(href) ">";
    text-decoration: none;
    color: #000000;
}

In Firefox (and probably Chrome but not IE8), text-decoration: none is ignored, and the underline stretches unattractively across the bottom of the url. The color however is correctly set to black for the url. Is there a way to make the text-decoration work?

The original question appended fixed size images instead of variable width text. Its answers use padding and background images to avoid having to use the text-decoration property. I'm still looking for a solution when the content is variable width text.

+1  A: 

I realise this isn't answering the question you're asking, but is there a reason you can't use the following (background-based approach):

a.file_pdf {
background-image: url(images/pdf.png);
background-position: center right;
background-repeat: no-repeat;
padding-right: 15px; /* or whatever size your .png image is plus a small margin */
}

As far as I know, the Firefox implementation of :after observes the property of the selector's class, not the psuedo-class. It might be worth experimenting with different doctypes, though? The transitional, rather than strict, sometimes allows for different results (albeit not always better results...).

Edit:

It appears that using

a:after {
    content: " <" attr(href) ">";
    text-decoration: none;
    color: #000000;
    background-color: #fff; /* or whatever colour you prefer */
}

overrides, or at least hides, the text-decoration. This doesn't really provide any kind of answer, but at least offers a workaround of sorts.

David Thomas
Firefox's behavior is according to specification. The pseudo-selector content is nested inside the selector as it should be. See my answer for clarification.
CptSkippy
I rewrote the question to clarify that I'm not using images at all.
palm3D
+2  A: 

IE8's implementation of the :before and :after pseudo-selectors is incorrect. Firefox, Chrome and Safari all implement it according to the CSS 2.1 specification.

5.12.3 The :before and :after pseudo-elements

The ':before' and ':after' pseudo-elements can be used to insert generated content before or after an element's content. They are explained in the section on generated text.

...

Cascading Style Sheets Level 2 Revision 1 (CSS 2.1) Specification

The specification indicates that the content should be inserted before or after the element's content, not the element (i.e. <element>content:before content content:after</element>). Thus in Firefox and Chrome the text-decoration you're encountering is not on the inserted content but rather on the parent anchor element that contains the inserted content.

I think your options are going to be using the background-image/padding technique suggested in your previous question or possibly wrapping your anchor elements in span elements and applying the pseudo-selectors to the span elements instead.

CptSkippy
After some more testing, I found out that `text-decoration` isn't applied, but `color` is. How does that behavior follow from the spec?
palm3D
@palm3D: What you are not understanding is that the pseudo-selectors are not inheriting text-decoration, the anchor's text-decoration is just showing through. If you set a text-decoration for the pseudo-selector, it is rendered on top of the selector's text-decoration. Additionally if you set a background-color to the pseudo-selector it correctly blots out the text-decoration of the selector in Firefox, Chrome and Safari. Also switching between rendering modes in IE8/IE7 changes handling of pseudo-selectors dramatically so watch your DTD.
CptSkippy
A: 

You can autoselect links to pdf-files by:

a[href$=".pdf"]:after { content: ... }

IE less than 8 can be enabled to work properly by implementing this link in the head of the html-file:

<!--[if lt IE 8]><script src="http://ie7-js.googlecode.com/svn/version/2.0(beta3)/IE8.js" type="text/javascript"></script><![endif]-->

It works also very good in al IE versions when you use the after-before-content-thing for dosplaying quotation marks.

I rewrote the question to clarify that I'm not interested in selectors, only the behavior of `text-decoration` in the `:after` pseudo-class.
palm3D
A: 

Position the content absolutely as follow:

a {
    position: relative;
    margin: 0 .5em;
    font-weight: bold;
    color: #c00;
}
a:before,
a:after {
    position: absolute;
    color: #000;
}
a:before {
    content: '<';
    left: -.5em;
}
a:after {
    content: '>';
    right: -.5em;
}

This works for me in Firefox 3.6, not tested in any other browsers though, best of luck!

Daniel