Requirements
.Childmust fill 100% of viewport in despite of.Parenthas side paddings..Parent's side paddings are unknown at advance for the.Child(assume that the.Childis a reusable component which does not know about environment in which it used)- The scrollbar width is broswer-dependent, thus it's width is unknown at advance and could not be hard-coded.
.Childmust be fully visible in length.
Solution attempt
.Parent {
background: #BBDEFB;
padding: 0 20px;
}
.Child {
width: 100vw;
margin-left: calc(-0.5*(100vw - 100%));
/* Child does not know that `Parent's` paddings are 20px */
height: 40px;
background: #FF8F00;
border: 5px solid #283593;
}
.Dummy {
height: 1000px;
background: #E1BEE7;
}
<div class="Parent">
<div class="Child"></div>
<div class="Dummy"></div>
</div>
The Child's left and right borders are not visible.
I suppose the cause is a scrollbar.
Can we respect the scrollbar?