How can I set the SPAN to align on both sides and above the table?

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

How can I put these spaces (they can be changed to any element), so depending on how big the table is (not defined anywhere and should not be), the spans are located directly above the left side of the table and the right side of the table.

Example:

ab
table0
table1
table2

(where a is the left lane and b is the right space)

PS You can change any internal html table table.

+3
source share
7 answers

Doesn’t place them relatively, nor Rob Allen will answer, they put them at the farthest points of the browser, not within the width of the table.

It’s good that they will be connected by the width of their container, and Rob’s answer will make the width of the table and container 100%.

, , - ( ), - DIV .

+2
<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>
+5

, . , . , IE5.5, IE6 .

  <style>
  .tablediv {
  float:left; /* this is a must otherwise the div will take a full width of our page and this way it wraps only our content (so only the table)   */
  position:relative; /* we are setting this to start the trickie part */  
  padding-top:2.7em; /* we have to set the room for our spans, 2.7em is enough for two rows otherwise try to use something else; for one row e.g. 1.7em */
  }
  .leftspan {
  position:absolute; /* seting this to our spans will start our behaviour */
  top:0; /* we are setting the position where it will be placed inside the .tablediv */
  left:0;
  }
  .rightspan {
  position:absolute; 
  top:0; 
  right:0; 
  }
  </style>
<div class="tablediv">
 <span class="leftspan">Left text</span>
 <span class="rightspan">Right text <br /> with row</span>
  <table border="1">
   <tr><td colspan="3">Header</td></tr>
   <tr><td rowspan="2">Left content</td><td>Content</td><td rowspan="2">Right content</td></tr>
   <tr><td>Bottom content</td></tr>
  </table>
</div>
 <!-- If you don't want to float this on the right side of the table than you must use the clear style -->
 <p style="clear:both">
  something that continues under our tablediv
 </p>

- , .tablediv, . float:left; to display:inline-block; , IE7 .

, , . , .tablediv , . , .

+2

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

+1
source
<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, just as Rob Allen doesn’t answer, they put them at the far end of the browser not in the width of the table.

0
source

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

0
source

I generally can’t think of how to set the width of the table to something. In my case, I select 100%, which extends to the rapper width 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>
0
source

Source: https://habr.com/ru/post/1698612/


All Articles