Using the last line of an inline element as the width for :after pseudo element

I'm facing an issue that I'm struggling to overcome.

This is best demonstrated with an example I guess:

As a fiddle: http://jsfiddle.net/wchv2hmn/3/

In the browser:

div {
    background-color: blue;
    text-align: center;
}
span {
    position: relative;
    background-color: green;
    
}
span:after {
    content: '';
    display: block;
    position: absolute;
    left: 0;
    right: 0;
    height: 10px;
    width: 100%;
    background-color: red;
}
<div>
    <span>
        htejuteujetjtjehrehreheherhrehrehre sghosgjosjoskoskfosjofshohofshofusofhrehrhrehehhrehrherheheuorfos
    </span>
</div>

You need to set the span as block element. Html

<div>
<span>
    htejuteujetjtje  sghosgjosjoskoskfosjofshohofshofusofuorfos
</span>
</div>

CSS

div {
background-color: blue; 
}
span {
position: relative;
background-color: green;
}

span{display:block;}

span:after {
content: '';
display: block;
height: 10px;
width: 100%;
background-color: red;
position: absolute;
}

Add display:inline-block to span style

 span {
     position: relative;
     background-color: green;
     display:inline-block;
 }

Result:

链接地址: http://www.djcxy.com/p/88398.html

上一篇: 宽度:100%

下一篇: 将内联元素的最后一行用作伪元素之后的宽度