Trying to position two label
elements on either side of a div
container has been tricky. Despite using various display properties like display: block
and display: inline-block
, the margins are not behaving as expected.
div {
color: #ffffff;
background-color: #3f3f3f;
}
label:nth-of-type(1) {
margin-left: 5px;
}
label:nth-of-type(2) {
display: block;
<!-- display: inline-block; -->
margin-right: 5px;
margin-left: auto;
}
<div>
<label>Left side label</label>
<label>right side label</label>
</div>
The issue becomes evident when the code is executed, with the second label failing to adhere to the specified margins and appearing below the first one.