首页 > 伪类before/after中的图片大小是不是不能设置的?

伪类before/after中的图片大小是不是不能设置的?

    #center_box:before{
        content:url(http://localhost/quding/photos/u14.png);
        position: absolute;
        width:1000px;
        height:200px;
        z-index: 100;
        top: -110px;
    }

随我怎么调width,height都没变化.


你可以把图片设为背景图片,通过bakckground-size来设置大小

#center_box:before{
    content:'';
    background-image:url(http://localhost/quding/photos/u14.png);
    background-size:1000px 200px;
    position: absolute;
    width:1000px;
    height:200px;
    z-index: 100;
    top: -110px;
}

:before /:after伪元素默认是一个行内元素,所以这个元素设置width/height是无效的
就像你对a元素设置width/height一样
设置position: absolute;后这个元素的display属性计算为block值;
但是设置的width/height针对的是:before/:after生成的匿名替换元素,而不是其中的content
所以图片的大小是没有效果的

【热门文章】
【热门文章】