It seems like the intention here is to evenly distribute the remaining white space (40% of the parent width) between the two span
elements while also managing the spacing around them within the parent container.
An approach to achieve this would be setting the left and right margins of the first span
to 13.3333% (which is 40% divided by 3). By floating the span
elements, they will naturally align next to each other, considering the assigned margin values.
As for the second span
, it doesn't require any margin adjustments as it will automatically position itself to the right of the first span
.
To contain the floated elements properly, it is recommended to add overflow: auto
to the parent container.
.foo {
width: 50%;
margin: auto;
background-color: blue;
overflow: auto;
}
.bar {
width: 30%;
background-color: red;
float: left;
text-align: center; /* optional... */
}
.bar:first-child {
margin-left: 13.3333%;
margin-right: 13.3333%;
}
<div class='foo'>
<span class='bar'>one</span>
<span class='bar'>two</span>
</div>