Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

div floating over table

Tags:

html

I am trying to get a div to float over a table so it will be on top of all the text?

like image 419
Rickstar Avatar asked Dec 23 '09 23:12

Rickstar


People also ask

Why should we use div instead of table?

Using div is better than using table because of easy control of the in the design and it can be container for controls than table and the table is mainlt used to group data with simillar structure so it's design is for this task but div is considered as container mainly than table.

Can you put a table in a div?

Yes you can put table tag inside div tag . It's 100% valid.

Can you float a table CSS?

The float property creates a floating box. The floating table can be created by applying this property to the TABLE element.


1 Answers

Check out absolute positioning, and possibly z-index as well (although if this is your only absolutely-positioned content, you won't need it). Although there are other ways to get things to overlap, that's probably the most relevant for you.

Very simple example:

CSS:

#target {
  position: absolute;
  left: 50px;
  top: 100px;
  border: 2px solid black;
  background-color: #ddd;
}

HTML:

<p>Something before the table</p>
<div id="target">I'm on top of the table</div>
<table>
  <tbody>
    <tr>
      <td>Text in the table</td>
      <td>Text in the table</td>
    </tr>
    <tr>
      <td>Text in the table</td>
      <td>Text in the table</td>
    </tr>
    <tr>
      <td>Text in the table</td>
      <td>Text in the table</td>
    </tr>
    <tr>
      <td>Text in the table</td>
      <td>Text in the table</td>
    </tr>
  </tbody>
</table>

Live copy | source

like image 95
T.J. Crowder Avatar answered Sep 21 '22 03:09

T.J. Crowder