css - 伪类before/after中的图片大小是不是不能设置的?
大家讲道理
大家讲道理 2017-04-17 11:32:20
0
2
1106
    #center_box:before{
        content:url(http://localhost/quding/photos/u14.png);
        position: absolute;
        width:1000px;
        height:200px;
        z-index: 100;
        top: -110px;
    }

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

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all(2)
大家讲道理

You can set the image as a background image and set the size through 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 pseudo-element is an inline element by default, so setting width/height on this element is invalid
Just like you set width/height on a element
Set position: absolute; after this The display attribute of the element is calculated as the block value;
but the set width/height is for the anonymous replacement element generated by :before/:after, not the content
, so the size of the image has no effect

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template