13

If I had two tables?

<table class="one"> and... <table class="two">

And the CSS looks like:

table.one {
    position: relative;
    float: left;
}
table.two {
    position: relative;
    float: right;
}

It is not working...

Olian04
  • 6,480
  • 2
  • 27
  • 54
Elias7
  • 12,285
  • 13
  • 35
  • 35

5 Answers5

22

Don't use position:relative, just provide width for each table in order to float properly.

table.one {
    float:left;
    width:45%;
}

table.two   {
    width:45%;
    float:right;
}​
irfanmcsd
  • 6,533
  • 7
  • 38
  • 53
3

You can simply define float: left to your table class it will come automatically next to each other:

table {
    float:left;
    background:yellow;
    margin-left:10px;
}
<table>
    <tr>
        <td>Table 1</td>
    </tr>
    <tr>
        <td>blah blah</td>
        <td>blah blah</td>
        <td>blah blah</td>
    </tr>

</table>

<table>
    <tr>
        <td>Table 2</td>
    </tr>
    <tr>
        <td>blah blah</td>
        <td>blah blah</td>
        <td>blah blah</td>
    </tr>
</table>
Olian04
  • 6,480
  • 2
  • 27
  • 54
Shailender Arora
  • 7,674
  • 2
  • 31
  • 35
2

Try giving them a width as well. 40% each should be a good test.

Ryan Potter
  • 835
  • 1
  • 11
  • 25
1

Hey it working i give you live demo now check this

and now you can do thing two option as like this

Option one

table.one {
  position:relative;
  float:left;
  border:solid 1px green;
}

table.two {
  position:relative;
  float:right;
  border:solid 1px red;
}
<table class="one">
  <tr>
    <td>hello demo here</td>
  </tr>
</table>

<table class="two">
  <tr>
    <td>hello demo here 2</td>
  </tr>
</table>

Option two

<table class="one" align="left" border="1">
  <tr>
    <td>hello demo here</td>
  </tr>
</table>

<table class="two" align="right" border="1">
  <tr>
    <td>hello demo here 2</td>
  </tr>
</table>
Olian04
  • 6,480
  • 2
  • 27
  • 54
Rohit Azad Malik
  • 31,410
  • 17
  • 69
  • 97
-1

What do you mean it's not working?

The CSS that you have will put one table on each side of the parent element. If you're looking for them to be float directly against each other rather than on opposite sides of the parent you'll want 'float: left;' in both of them (or conversely 'float: right;' in both of them).

arychj
  • 711
  • 3
  • 21