I’m interested how could I create a table like layout working only with div elements. I read a lot about display and float style attributes and I think this code should layout content as I want, but I see a table with the second row moved to one position below.
I expect to see:
left1 right1
left2 right2
but I see
left1
left2 right1
right2
Here my CSS
.big {
display: inline-block;
}
.small {
display: block;
}
.left {
display: inline;
}
.right {
display: inline;
float: right;
}
And here my html file:
<div class="big">
<div class="small">
<div class="left">left1</div>
<div class="right">right1</div>
</div>
<div class="small">
<div class="left">left2</div>
<div class="right">right2</div>
</div>
I managed to create the table (add rule width: 100px to the .small selector) but I don’t want to specify width of my DIV elements, because they could have different width.
Thanks
If it’s a true table layout, it’s appropriate to use an html table. If it is not a true table layout, here’s what you need in your CSS if you were to keep the HTML unchanged:
“clear: both” is sort of like a carriage return (ding! for all you with memory of typewriters)
“float:left” puts stuff next to each other horizontally instead of the natural vertical stacking of box elements (like divs).
For my own table-ish CSS layouts, I use only two classes, “row” and “column”, as follows:
Here’s how I’d do your little example:
Feel free to ask any follow-ups about the nuances of the CSS markup and what it’s doing.