CSS - How to make child div wider than parent div

By using calc

Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
html,
.parent {
height: 100%;
width: 100%;
text-align: center;
padding: 0;
margin: 0;
}
.parent {
width: 50%;
max-width: 800px;
background: grey;
margin: 0 auto;
position: relative;
}
.child-element {
position: relative;
width: 100vw;
left: calc(-50vw + 50%);
height: 50px;
background: blue;
}

How do we make a full-browser-width container when we’re inside a limited-width parent?

Source

1
2
3
4
5
6
7
8
.full-width {
width: 100vw;
position: relative;
left: 50%;
right: 50%;
margin-left: -50vw;
margin-right: -50vw;
}