Applying text-decoration on css generated content in IE

前端 未结 6 1993
抹茶落季
抹茶落季 2020-12-17 00:15

It seems IE doesn\'t care for text-decoration: none; defined for a:before pseudo element (or pseudo class).

Here is a JS Fiddle: http://jsf

6条回答
  •  隐瞒了意图╮
    2020-12-17 00:39

    I'm aware this is a rather elderly thread, but having just been up against this problem in IE 11, and unable to find much help, I decided to experiment. Aided by a significantly improved dev tools than in the earlier versions I managed to figure it out - for what I'm working on at any rate. Chances are it'll work for others as well, although you might need to tweak. YMMV.

    The HTML:

  • Whatever
  • The CSS (edited after @frnhr pointed out that the initial version I posted didn't actually work):

    a {
        display: block;
        position: relative;
        padding-left: 15px;
        text-decoration: none;
    }
    
    a:hover {
        text-decoration: underline;
    }
    
    a:before {
        position: absolute;
        left: 0;
        top: 0;
        height: calc(100% - 2px);
    
        overflow: hidden;
    
        content: ">";
    }
    

    The secret sauce is setting the height and the overflow: hidden; line; it means that the underline is still there but outside the viewport provided by pseudo element, and so never gets seen on screen. It also works across other browsers (tested on Chrome and Firefox as well). Depending on your existing styling you'll probably want to tweak the pixel value in the calc() value.

    See http://jsbin.com/biwomewebo/1/edit?html,css,output

提交回复
热议问题