简体   繁体   English

延伸到页面高度的:: after和:: before伪元素的背景图像

[英]Background image for ::after and ::before pseudo elements that extend to the height of the page

I have a <div class="page"> centered at my page, and I'd like to have two background images running along the left and right edge of this element. 我有一个<div class="page">以我的页面为中心,我想在此元素的左右边缘放两个背景图像。

I've set up the .page::before and .page::after pseudo-elements and they seem to work great, but the background images repeat themselves up to the end of the visual viewport and not the whole page. 我已经设置了.page::before.page::after伪元素,它们看起来很不错,但是背景图像会在视觉视口的末端而不是整个页面重复出现。

I've tried several things, playing with the position:... of the div , or setting height: 100% to html and/or body but to no avail. 我尝试了几件事,使用divposition:...或将height: 100%设置height: 100%设置为html和/或body但无济于事。

I've made a JsFiddle demo here to illustrate the problem. 我在这里做了一个JsFiddle演示来说明问题。 Ideally, I'd like not to mess with the html markup. 理想情况下,我不希望弄乱html标记。

Any ideas? 有任何想法吗?

EDIT : Including the markup and css here for future reference. 编辑 :在此处包括标记和CSS,以供将来参考。

HTML : HTML

<div class="page">__long content here__</div>

CSS 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;
}

Positioning .page relatively seems to work : 定位.page相对似乎有效

.page {
    position: relative;
    background-color: white;
    width: 400px;
    margin: 0 auto;
    padding: 1em;
}

Without it, the height: 100% on its pseudo-elements refers to the height of the viewport instead because they are absolutely-positioned. 如果没有它,那么height: 100%在其伪元素上的height: 100%是指视口的高度,因为它们是绝对放置的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM