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. dockerfile - 我用docker build的時候出現下邊問題 麻煩幫我看一下2. android-studio - Android studio導入老版本的2048項目報錯3. 為什么我ping不通我的docker容器呢???4. PHP類屬性聲明?5. php mail無法發送郵件6. PHP 怎么api獲取json數據7. PhpStorm 輸入php按tab后生成的起始結束標簽<php><php> 如何修改?8. 為什么要通過常量的方式拐彎抹角的寫呢,直接寫DSN之類的不好嗎9. 做一個抽獎系統10. 請問一下各位老鳥 我一直在學習獨孤九賤 現在是在tp5 今天發現 這個系列視頻沒有實戰
