[英]Making a background image full width when inside a set container
I have a container that is set at 1200px.我有一个设置为 1200px 的容器。 Inside that container i have div that has a background image set via css.
在那个容器内,我有一个 div,它有一个通过 css 设置的背景图像。 I need to make this background image "escape" its full width container that it is trapped in and make it span the entire width of the page.
我需要让这个背景图像“转义”它被困在其中的全宽容器,并使其跨越页面的整个宽度。 How would i accomplish this?
我将如何做到这一点?
<div class="container">
<div class="hero">
<p>irrelevant stuff inside</p>
</div>
</div>
.container {
max-width: 1200px;
margin: 0 auto;
}
.hero {
background: url("https:example.com") center center no-repeat;
background-size: cover;
width: 100%;
}
CSS CSS
.hero {
position: absolute;
left: 0;
background: url('img.jpg');
width: 100%;
}
Note: .container element should have 'position:static' .注意: .container元素应该有'position:static' 。 Any other value will not work.
任何其他值都不起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.