Check out my solution on this interactive demo. The code is provided below for reference.
The benefit of this approach is that the content container will automatically adjust its size when the parent container's dimensions change, maintaining its margins while keeping the right sidebar consistently positioned to the right.
I hope you find this useful!
Note: In the demo linked above, the width of the content
container may appear narrow due to window size constraints. Try resizing the window {Click and drag the dividers} to observe the responsive behavior.
<div class="container">
<div class="content">
centered content
</div>
<div class="right">
right
<div>
</div>
.container {
width:100%;
position:relative;
}
.container .content {
width:auto;
margin:0 200px;
background:green;
}
.container .right {
width:200px;
position:absolute;
top:0px;
right:0px;
background:#f00;
}
.content, .right {
height:300px
}