I have multiple div's I want to display in a horizontal row. Normally, the way I'd do this is to simply float them to the right and put them in the markup in reverse order like so:
<div> <div style="float:right">Right</div> <div style="float:right">Middle</div> <div style="float:right">Left</div> </div>
I'm trying to accomplish a similar thing, float div's to the right, but I can't reverse their order in the markup for SEO reasons. The left div needs to be first in the code.
Is there a simple way to do this without resorting to positioning things absolutely?
Use CSS property to set the height and width of div and use display property to place div in side-by-side format. float:left; This property is used for those elements(div) that will float on left side. float:right; This property is used for those elements(div) that will float on right side.
The float CSS property places an element on the left or right side of its container, allowing text and inline elements to wrap around it. The element is removed from the normal flow of the page, though still remaining a part of the flow (in contrast to absolute positioning).
The elements after the floating element will flow around it. The elements before the floating element will not be affected. If the image floated to the right, the texts flow around it, to the left and if the image floated to the left, the text flows around it, to the right.
You could apply a text-align: right
to the container and a display: inline-block
in place of the floating:
<div style="text-align: right"> <div style="display:inline-block">Left</div> <div style="display:inline-block">Middle</div> <div style="display:inline-block">Right</div> </div>
DEMO
Using display:inline-block
might not work as expected with elements of variable height.
So you might want to use:
<div style="float: right"> <div style="float:left">Left</div> <div style="float:left">Middle</div> <div style="float:left">Right</div> </div>
See: demo of both -- inline and float-float.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With