css - 伪类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都没变化.
问题解答
回答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所以图片的大小是没有效果的
相关文章:
1. 老师,你这两条斜杠的是怎么注释的?2. mac连接阿里云docker集群,已经卡了2天了,求问?3. angular.js - angularjs ng-repeat 不能刷新4. PHP单例模式5. docker 下面创建的IMAGE 他们的 ID 一样?这个是怎么回事????6. angular.js - 用angular2-cli打包项目之后,跳转路由刷新会报404的错误7. css3 - css字体样式加填充色而不是背景色8. node.js - 来帮我捋一下node中fs模块watch实现原理9. docker镜像无法删除,请求解决办法。10. angular.js - angularJS最简单方法实现点击checkbox,button变亮