I've styled two div
elements with the properties below:
.elem1 {
width: 47.5%;
margin-right: 2.5%;
display: inline-block;
}
.elem2 {
width: 47.5%;
margin-right: 2.5%;
display: inline-block;
}
Note: When I decrease the margins to 2.25%
, the elements align inline within the parent body
. However, if I wrap them in a narrower div
, the second element breaks to a new line.
Even though they add up to 100%
of the parent's width
, the elements are not consistently positioned inline. How can this be resolved to ensure they always stay inline?
The goal is to essentially have them float without using the float
property.
You can view the fiddles below for better visualization:
The CSS solution should only involve the two elem
elements as no user-defined parent container might be present.