Alternate Solution 1: Adding Padding
To simplify the CSS, you can just set the size for the outer div and add box-sizing: border-box
to prevent the padding from affecting the width of the div.
#out {
width: 700px;
padding: 10px;
box-sizing: border-box;
background: lightblue;
}
No need for positioning the other div. Simply give it a height, and it will automatically stretch the outer div:
#in {
height: 20px;
background: white;
}
Click here to view the solution on CodePen
Another Approach: Using a Border
If your aim is to have a blue border, there's no necessity for two divs. Consider this alternative:
#out {
width: 700px;
}
#in {
height: 20px;
border: 10px solid lightblue;
}
In this scenario, you only require one div. Remove #out completely and transfer the width
property to #in.
Check out the example on CodePen here