css - 偽類(lèi)before/after中的圖片大小是不是不能設(shè)置的?
問(wèn)題描述
#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都沒(méi)變化.
問(wèn)題解答
回答1:你可以把圖片設(shè)為背景圖片,通過(guò)bakckground-size來(lái)設(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是無(wú)效的就像你對(duì)a元素設(shè)置width/height一樣設(shè)置position: absolute;后這個(gè)元素的display屬性計(jì)算為block值;但是設(shè)置的width/height針對(duì)的是:before/:after生成的匿名替換元素,而不是其中的content所以圖片的大小是沒(méi)有效果的
相關(guān)文章:
1. [python2]local variable referenced before assignment問(wèn)題2. 求救一下,用新版的phpstudy,數(shù)據(jù)庫(kù)過(guò)段時(shí)間會(huì)消失是什么情況?3. mysql - 如何在有自增id的情況下,讓其他某些字段能不重復(fù)插入4. python小白,關(guān)于函數(shù)問(wèn)題5. django - Python error: [Errno 99] Cannot assign requested address6. angular.js - 百度支持_escaped_fragment_嗎?7. java - 線(xiàn)上應(yīng)用,如果數(shù)據(jù)庫(kù)操作失敗的話(huà)應(yīng)該如何處理?8. node.js - win 下 npm install 遇到了如下錯(cuò)誤 會(huì)導(dǎo)致 無(wú)法 run dev么?9. python小白 關(guān)于類(lèi)里面的方法獲取變量失敗的問(wèn)題10. Python2中code.co_kwonlyargcount的等效寫(xiě)法
