Log in

View Full Version : Two Tables in one line



costas
01-28-2007, 03:20 PM
Hi to all,
I'm wondering how can I put two tables in the same line!
Thanks in advance!

Twey
01-28-2007, 03:48 PM
Use:
display: inline;

djr33
01-29-2007, 12:53 AM
Would the same apply to divs?

mburt
01-29-2007, 01:13 AM
Nope, for divs you have to use:

float:left

Twey
01-29-2007, 01:51 AM
The same would apply to divs, yes. There are fundamental differences between floating an element and making it inline.

djr33
01-29-2007, 02:04 AM
<div style="display:inline;">testing</div><div style="display:inline;">testing2</div>Becomes: testingtesting2

Very nice.

Now using divs instead of tables is actually possible without bizarre css stuff, like absolute positioning which doesn't work in many cases anyway. Heh. I wish I'd known this before....


One thing remains, though... could you set the height/width of each of those elements as well?

Twey
01-29-2007, 02:10 PM
No. That's where floating comes in. Using display: inline; causes them to be rendered as inline elements, like <span>, whose size and position is dictated by the contents. Floating them, on the other hand, means keeping them as block-level elements, but rather than having them take up all the space on a line, stacks them against one side of the parent element. Try it:
<div style="border: 3px solid blue; float: left; width: 40&#37;; height: 20em;">Testing</div><div style="border: 3px solid red; float: left; width: 40%; height: 20em;">Testing2</div>

costas
01-30-2007, 12:35 PM
Hey guys, thanks a lot!

djr33
01-31-2007, 01:52 AM
Thanks, Twey. Still seems like it would be a hassle to replace tables, then.

Twey
01-31-2007, 03:31 PM
It can be, yes, and there are some layouts that simply can't be done. It's usually easy enough, though.