您的位置:首页技术文章
文章详情页

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

【字号: 日期:2023-07-17 09:04:29浏览:99作者:猪猪

问题描述

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

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

问题解答

回答1:

你可以把图片设为背景图片,通过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;}回答2:

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

标签: CSS
相关文章: