您的位置:首頁技術文章
文章詳情頁

css - 偽類before/after中的圖片大小是不是不能設置的?

瀏覽:164日期:2023-07-17 09:04:29

問題描述

#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
相關文章:
国产综合久久一区二区三区