I wonder if it's possible to have a div stretch to 100vw
, while being inside a relative
parent div with limited width. And in the process also not losing it's height inside the document, as it would when setting position to absolute.
Is it possible with pure css? Or do I need some jQuery / JS?
body {
background: #f0f0f0;
text-align: center;
}
.parent {
max-width: 300px;
height: 300px;
margin: auto;
position: relative;
background: white;
}
p {
padding: 20px;
}
#banner {
padding: 20px;
background: black;
color: white;
}
<div class="parent">
<p>My relative parent container,<br>with a fixed width.</p>
<div id="banner">
My full width banner
</div>
<p>...</p>
</div>
Anyone has any experience in getting this to work? Any and all tips are much appreciated. Thanks!