tags:

views:

3372

answers:

6
<div>
<span>left</span>
<span>right</span>
<!-- new line break, so no more content on that line -->
<table> 
...
</table>
</div>

How can I position those spans (they can be changed to any element) so that depending on how big the table is (not defined anywhere, and shouldn't be) the spans are positioned just on top of the left side of the table and the right side of the table.

Example:

a    b
table0
table1
table2

(where a is the left span, and b is the right span)

P.S. You can change anything bar inner table html.

+1  A: 

if you have divs instead of span, try float:left for span a and float:right for span b

Ramesh
+1  A: 
<style type="text/css">
    #wrapper, #top, #tableArea
     {
       width: 100%;
       padding: 10px;
       margin: 0px auto;
      }

     #top
      {
        padding: 0px;
      }

      #leftBox, #rightBox
      {
          margin: 0px;
          float: left;
          display: inline;
          clear: none;
       }

       #rightBox
        {
            float: right;
        }
     </style>
<div id="wrapper">
    <div id="top">
        <div id="leftBox">A</div>
        <div id="rightBox">b<</div>
    </div>
    <div id="tableArea">
        <table> ... </table>
    </div>
</div>
Rob Allen
please refrain from using px values like 10px. We are on our way to resolution independance. Use em and ex instead, they scale with the text size and therefore well with the whole output.
ypnos
Noted. I've struggled with em measurements in the past.
Rob Allen
This, of course, does not work. Put some borders on the table and the divs to give a visual clue about what is being displayed. The tablearea and wrapper both take 100%, but the table only takes the space needed.
Traingamer
If all you did was copy paste this into your page, you would be correct. However, as the table grows, the other sections will grow as well. These tags can be dropped into another wrapper that sets a smaller width. This is a starting point for the OP and readers to go off of - not free code.
Rob Allen
A: 
<div>
<div style="float:left">a</div><div style="float:right">b</div>
<br style="clear: both">
aaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
aaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
aaaaaaaaaaaaaaaaaaaaaaaaaaa<br />
</div>

Doesn't place them relatively, nor does Rob Allen's answer, they put them at the far reaches of the browser not, within the table width.

+1  A: 

Doesn't place them relatively, nor does Rob Allen's answer, they put them at the far reaches of the browser not, within the table width.

Well they are going to be bound by their container width and Rob's answer makes both the table and container width 100%.

The only solution I can think of off hand is to put in a row in your table with a single column (spanning all columns) and in that row have your floated DIVs.

Graphain
A: 

@Graphain, you might have something there. And then just use fload: left and float right I assume?

Now - you'd just put them cells on either side of the table.
Rob Allen
Well either float:left, float:right in one cell or, (depending on if you can split the colspan evenly I guess although width may be able to still split things properly) use two cells with text-align in each.
Graphain
A: 

I can't think of anyway, except to set the width of the table to something. In my case I choose 100%, which stretches to the width of the rapper at 50em:

<style type="text/css">
#wrapper {
    width: 1%;
    min-width:50em;
    padding: 10px;
}
#mainTable {
    width:100%;
}

#leftBox {
    float: left;
}

#rightBox {
    float: right;
}
</style>
<div id="wrapper">
    <div id="leftBox">A</div>
    <div id="rightBox">b</div>
    <br style="clear: both" />
    some text some text some text some text some text <br />
    some text some text some text some text some text <br />
    some text some text some text some text some text
    <table id="mainTable" border="1"><tr><td>test</td><td>test 2</td></tr></table>
</div>
Darryl Hein