On the content element use
margin-left: calc(A - B);
where
A = 1/2 width of the container
B = 1/2 width of the content
Follow a code Example of 3 nested content of different dimensions.
HTML:
<div class="page-wrapper">
<div class="container container 1">
<p>Container 1 - width: 600px</p>
<div class="content content-1">Content 1: width: 800px</div>
</div>
</div>
<div class="page-wrapper">
<div class="container container 2">
<p>Container 2</p>
<div class="content content-2">Content 2 - width: 160%</div>
</div>
</div>
<div class="page-wrapper">
<div class="container container 3">
<p>Container 3</p>
<div class="content content-3">Content 3 - width: 1024px</div>
</div>
</div>
Code example CSS:
.page-wrapper {
width: 1024px;
display: flex;
align-items: center;
justify-content: center;
border: solid 1px #000000;
padding: 20px 0;
}
.container {
width: 600px;
height: 300px;
background: #FF0066;
text-align: center;
}
.content {
height: 200px;
background-color: #666666;
box-sizing: border-box;
max-width: 100vw; /* do not exceed the viewport width; */
}
.content-1 {
width: 800px;
margin-left: calc(50% - 400px); /* this center the content */
}
.content-2 {
width: 160%;
margin-left: calc(50% - 80%); /* this center the content */
}
.content-3 {
width: 1024px;
margin-left: calc(50% - 512px); /* this center the content */
}
The working codepen here: https://codepen.io/Davevvave/pen/XWBepBM