[英]Background image for ::after and ::before pseudo elements that extend to the height of the page
我有一個<div class="page">
以我的頁面為中心,我想在此元素的左右邊緣放兩個背景圖像。
我已經設置了.page::before
和.page::after
偽元素,它們看起來很不錯,但是背景圖像會在視覺視口的末端而不是整個頁面重復出現。
我嘗試了幾件事,使用div
的position:...
或將height: 100%
設置height: 100%
設置為html
和/或body
但無濟於事。
我在這里做了一個JsFiddle演示來說明問題。 理想情況下,我不希望弄亂html標記。
有任何想法嗎?
編輯 :在此處包括標記和CSS,以供將來參考。
HTML :
<div class="page">__long content here__</div>
CSS
.page {
background-color: white;
width: 400px;
margin: 0 auto;
padding: 1em;
}
.page::before {
content: '';
background-image: url(__some background image__);
position: absolute;
width: 94px;
height: 100%;
top: 0;
margin-left: -100px;
}
.page::after {
content: '';
background-image: url(__some background image__);
position: absolute;
width: 94px;
height: 100%;
top: 0;
margin-left: 995px;
}
定位.page
相對似乎有效 :
.page {
position: relative;
background-color: white;
width: 400px;
margin: 0 auto;
padding: 1em;
}
如果沒有它,那么height: 100%
在其偽元素上的height: 100%
是指視口的高度,因為它們是絕對放置的。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.