I try to build fluid layout using percentages as widths. Do do so i tried this:
<div style="width:50%; display:inline-table;">A</div> <div style="width:50%; display:inline-table;">B</div>
In that case they wont stand in one line, but if i remove line break between them, like this:
<div style="width:50%; display:inline-table;">A</div><div style="width:50%; display:inline-table;">B</div>
then it works fine. Where is the problem? How can i do someting like that but without using absolute position and float.
p.s. sorry for english. p.s.s. i hope i good explain my problem
Using float and margin The left div is styled with width:50% and float:left – this creates the green colored div that horizontally covers half of the screen. The right div is then set to margin-left:50% – this immediately places it to the right of the left div.
To display multiple div tags in the same line, we can use the float property in CSS styles. The float property takes left, right,none(default value) and inherit as values. The value left indicates the div tag will be made to float on the left and right to float the div tag to the right.
By default <DIV> does cause a line break.
The most common way to place two divs side by side is by using inline-block css property. The inline-block property on the parent placed the two divs side by side and as this is inline-block the text-align feature worked here just like an inline element does.
The problem is that when something is inline, every whitespace is treated as an actual space. So it will influence the width of the elements. I recommend using float
or display: inline-block
. (Just don't leave any whitespace between the divs).
Here is a demo:
div { background: red; } div + div { background: green; }
<div style="width:50%; display:inline-block;">A</div><div style="width:50%; display:inline-block;">B</div>
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