views:

393

answers:

6

Hello,

I have following code:

<table>
    <tr>
        <td>Table 1</td>
    </tr>
</table>

<table>
    <tr>
        <td>Table 2</td>
    </tr>
</table>

Very unfortunately, a line break is inserted between these two tables. I have tried putting them both in a single span and setting the whitespace to nowrap, but at no avail. Please, could you tell me how I can simply put these elements in a single row, without setting the float attribute in CSS and without surrounding each table with a <td> {table} </td> and then putting this in a table row.

Thanks a lot in advance. I have asked Google, but it just wouldn't say anything ^^ StackOverflow remained silent so far, too

A: 

Try this css:

table {
  padding:0px;
  margin:0px;
}

Or you can hack into negative top-margin

table{
  margin-top:-20px;
}
Sarfraz
A: 

What if you float table 1 to the left, and table to to the right? By default, tables are "block" elements, so you could try display:inline.

Ken Ray
Making things line up: Float them to the same side, not to left-right. It will often just make everything else around so much harder to get right.
Arve Systad
A: 

or this:

<table border=1 style="position:absolute;width:100;height:30;left:0;top:100"> 
<tr> 
<td>aaaaa</td> 
</tr> 
</table> 
<table border=1 style="position:absolute;width:100;height:30;left:100;top:100"> 
<tr> 
<td>bbbbb</td> 
</tr> 
</table>
MUG4N
A: 

table{display:inline;} didn't work?

edl
nope. does not work. Although it is in one line, the table borders are cutting its content. It's totally wrong :(
arik-so
Can I see your css?
edl
A: 

You should use CSS for this, as it is a presentational issue. Why can't you use CSS?

This is how I'd do it. Simple, works in every browser and it easily adapts to surrouding layout elements. Give both tables a width that fits them in the containing element, and float both of them to the left. For example:

<div id="container">
  <table>...</table>
  <table>...</table>
</div>

#container { width: 500px; } 
table { width: 250px; float: left; }
Arve Systad
I can use CSS. I just did not want to make one table float left and the otehr one float right, but your solution seems interesting. I'll try it out now. Thanks ^
arik-so
Yep, I see. As i stated in a previous comment, floating left-right often complicates things around, and makes the layout very little adaptable to surrounding content. Floating things to the same side is better.
Arve Systad
+1  A: 

I found it!

One has to use the following settings for both tables:

display: inline-table;

Thanks for the inline, guys, thanks a lot, but at least, inline-table works ^^

Hope I helped...

arik-so