“text-decoration” and the “:after” pseudo-element, revisited

后端 未结 11 805
旧巷少年郎
旧巷少年郎 2020-11-27 18:43

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

相关标签:
11条回答
  • 2020-11-27 19:27

    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.

    0 讨论(0)
  • 2020-11-27 19:30

    As an alternative, you can use a bottom border rather than a text-decoration. This assumes that you know the color of the background

    a {
      text-decoration: none;
      border-bottom: 1px solid blue;
    }
    a:after {
      content: "foo";
      border-bottom: 1px solid white; /* same color as the background */
    }
    
    0 讨论(0)
  • 2020-11-27 19:32

    If you use display: inline-block on the :after pseudo, the text-decoration declaration will work.

    Tested in Chrome 25, Firefox 19

    0 讨论(0)
  • 2020-11-27 19:32

    The only thing that worked for me was declaring a separate repeated selector with the same text-decoration property that it was inheriting from its parent, then in the main selector, setting text-decoration to none.

    IE apparently does not know what to do when you set text-decoration: none on a pseudo element without that element having the text-decoration property declared (which by default, it has nothing declared by default). This makes little sense because it is obviously being inherited from the parent, but alas, now we have modern browsers.

    span.my-text {
      color: black;
      font-size: 12px;
      text-decoration: underline;
    }
    
    span.my-text:after {
      text-decoration: underline; // Have to set text-decoration here so IE knows it can be overwritten below
    }
    
    span.my-text:after {
      color: red;
      text-decoration: none; // In the same repeated selector, we can now overwrite text-decoration in our pseudo element.
    }
    
    0 讨论(0)
  • 2020-11-27 19:36

    Hi I was also having trouble with this as well and happened to stumble across a workaround.

    To get around it, I wrapped the URL in div and used something like this.

    .next_page:before {
        content: '(';
    }
    
    .next_page:after {
        content: ')';
    }
    
    0 讨论(0)
提交回复
热议问题