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

后端 未结 11 944
旧巷少年郎
旧巷少年郎 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: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.
    }
    

提交回复
热议问题