css - 偽類before/after中的圖片大小是不是不能設(shè)置的?
問題描述
#center_box:before{content:url(http://localhost/quding/photos/u14.png);position: absolute;width:1000px;height:200px;z-index: 100;top: -110px; }
隨我怎么調(diào)width,height都沒變化.
問題解答
回答1:你可以把圖片設(shè)為背景圖片,通過bakckground-size來設(shè)置大小
#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偽元素默認(rèn)是一個(gè)行內(nèi)元素,所以這個(gè)元素設(shè)置width/height是無效的就像你對(duì)a元素設(shè)置width/height一樣設(shè)置position: absolute;后這個(gè)元素的display屬性計(jì)算為block值;但是設(shè)置的width/height針對(duì)的是:before/:after生成的匿名替換元素,而不是其中的content所以圖片的大小是沒有效果的
相關(guān)文章:
1. angular.js - angular內(nèi)容過長(zhǎng)展開收起效果2. dockerfile - [docker build image失敗- npm install]3. 在windows下安裝docker Toolbox 啟動(dòng)Docker Quickstart Terminal 失??!4. docker-compose中volumes的問題5. golang - 用IDE看docker源碼時(shí)的小問題6. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題7. mac里的docker如何命令行開啟呢?8. 我在centos容器里安裝docker,也就是在容器里安裝容器,報(bào)錯(cuò)了?9. docker內(nèi)創(chuàng)建jenkins訪問另一個(gè)容器下的服務(wù)器問題10. nignx - docker內(nèi)nginx 80端口被占用

網(wǎng)公網(wǎng)安備