z-index IE8 bug on generated content with :after

后端 未结 4 1680
孤街浪徒
孤街浪徒 2021-02-02 10:48

This is a known error in IE8, look at the last bug here:
http://nicolasgallagher.com/css-typography-experiment/demo/bugs.html

Now, playing a bit with a simple e

4条回答
  •  忘了有多久
    2021-02-02 11:31

    No need to set z-indexes, just make sure you use :after instead of :before (demo):

    #target {
        position: relative;
        width: 200px;
        height: 200px;
    }
    #target>div{
        background: red;
        width: 200px;
        height: 200px;
    }
    #target:after {
        content: "after";
        position: absolute;
        top: 0;
        left: 10%;
        width: 100%;
        height: 100%;
        background: cyan;
    }​
    

    Since the generated content comes after #target, it will naturally be stacked above.

    BTW Whether a product is "sold" or not is semantic information, and so the correct semantic solution would be to include it in the HTML, rather than adding the image through CSS.

提交回复
热议问题