I'm not really sure what I need here but I want to position a div at the bottom of a nested table.
I have an outer table that is 100% wide and no height attribute. I have another table within that outer table where I am using the div. I want the div content to rest on the bottom of the inner table. I currently have the div in a <td> tag.
I've tried to use position:absolute; bottom:0; left:0; but it puts the div and its content at the very bottom of my screen.
How can I do this?
BTW: I know that I should be using 100% css on this project but I'm making a gradual transition. :)
Here is my code for the div
#messageBox {
width:95%;
height:35px;
margin:10px;
padding:10px;
font-family:Arial;
font-size:18px;
}
Here is the table code
<table cellpadding="0" cellspacing="0" border="0" style="width:60%;margin-left:auto;margin-right:auto;margin-top:30px;border:0px solid">
<tr>
<td colspan="2" style="height:85px;"><div id="messageBox">test</div></td>
</tr>
</table>
You need to set the <td> element in question to position: relative;. This way any absolutely positioned element will be positioned relative to it.
#messageBox {
width:95%; /* wrong calculation when you add with margin/padding makes overflow */
height:35px;
margin:10px;
padding:10px;
font-family:Arial;
font-size:18px;
border:1px solid red;
}
<table>
<tr>
<td colspan="2" style="height:185px; border:1px solid black; vertical-align:bottom;">
<div id="messageBox">test</div>
</td>
</tr>
</table>
I changed your td's height from 85px to 185px to make it obvious.
Preview:
Request (not overflow):
I'm using additional wrapper.
<table>
<tr>
<td colspan="2" style="height:185px; border:1px solid green; vertical-align:bottom;">
<div style="overflow:hidden; border:1px solid red;">
<div style="border:1px solid black; float:left; width:100px; margin:10px; padding:0px;">Test</div>
</div>
</td>
</tr>
</table>
Preview:
Oh the joys of working with tables. It seems that this won't work unless you set the display property of the table to block
You can try giving the outer innermost (my eyes failed me, sorry) table this style:
position: relative;
display: block;
You'll also need to add back in the position: absolute (I see you've taken that out, that is actually the correct method to use for this)
#messageBox {
position: absolute;
bottom: 0;
}
Do remember that this will change how the table works, and will probably break your site. See: http://jsfiddle.net/5xTXU/
Related
Why top/bottom border on <td> sticks out by 1px when table's container has certain width and when table is centered ?
Picture shows the problem:
HTML:
<body>
<table>
<tr>
<td style=" border-top:4px solid green;border-right:4px solid green;">data 1
<td>data 2
</table>
</body>
CSS:
table{
margin:10px auto;
border-collapse:collapse;
text-align:center;
line-height:30px;
}
td{
background-color:silver;
width:100px;
}
You are not closing the <td> and <tr>:
<td style=" border-top:4px solid green;border-right:4px solid green;">data 1
<td>data 2</td>
</tr>
Also, add the following CSS for:
Making borders even.
Making to use border-box layout.
CSS:
* {box-sizing: border-box;}
td {
background-color: silver;
width: 100px;
border: 4px solid silver;
}
Note: You might need to tinker a bit to get the right output. We can just advice you on the right direction.
Preview
Fiddle: https://jsfiddle.net/2vdf28xd/
It's because the width and height by default is calculated by the browser with
width = width + border left + border right + padding left + padding right
height = height + border top + border bottom + padding top + padding bottom
To avoid this, make sure the calculations are absolute with
td {
box-sizing: border-box;
}
Good luck!
I've figured out that this is a BUG in older versions of Firefox.
This behaviour does not happen in new FF version and other browsers.
You can add the following attribute for the table you might be using:
<table border="1">...</table>
Adding the border="1" attribute we can remove this 1px sticking out problem.
I have a table where each cell has some text in it. I want a div to pop up and to cover the table but when the div pops up, it covers the table's borders, but not the text. It looks as if the text in just on the div. I have played around with the background-color and opacity, but nothing seems to work. Can anyone help me?
P.S. I can not make the table disappear in anyway because the overlapping div will go away eventually.
Since you didn't post your code, I'm going to assume the problem is somehow related to
z-index:*;
so I created a fiddle where you can change the z-index and see the difference that makes using this code.
<html>
<head>
<style>
p{
margin:0;
position:relative;
z-index:3;
}
table, div{
width:100px;
height:100px;
}
div{
background-color:blue;
position:relative;
top:-100px;
z-index:2;
}
</style>
</head>
<body>
<table border="1">
<tr>
<td><p>1</p></td>
<td><p>2</p></td>
</tr>
<tr>
<td><p>3</p></td>
<td><p>4</p></td>
</tr>
</table>
</body>
</html>
JsFiddle
Note that for z-index to work position has to be set, like this
position:relative;
or
position:absolute;
or
position:fixed;
though I don't think fixed might fit your needs.
Your Question is Not Cleared.
Any way i hope that, this what u asked for...
HTML
<table cellspacing="0">
<tr>
<td>Hellossss
<span></span>
</td>
<td>English
<span></span>
</td>
<td>French
<span></span>
</td>
</tr>
</table>
CSS
table td{ border:3px grey solid; padding:0px; position:relative; width:100px}
span{content:"";position:absolute; width:100%;height:98%; background:green;
left:0;top:0; display:none}
td:hover span{display:block}
http://jsfiddle.net/edBQh/
I have a table, which I want to hide and show using jQuery. I want to add a 'close' button to the top right.
But the close button always appears behind the table, so not able to visible
How can I make the close button appear in front of the table please (not above/to the side), and therefore available to be clicked on?
<style>
table
{
border: 3px solid #000000;
align: center;
text-align: center;
color:#000000;
}
th,td
{
border-width: 2px;
border-color: #000000;
border-style: solid;
}
#RCLPage
{
display:block;
position:absolute;
z-index:100;
}
.close_box
{
background-image:url('../tsTest2/images/close.gif');
background-repeat:no-repeat;
background-position:right top;
position:relative;
z-index:101;
//height:10px;
}
#CPSTab
{
padding:10;
width:20em;
}
</style>
<div id="RCLPage">
<div class="close_box"></div>
<table id="CPSTab">
<thead>
<tr>
<th colspan="2">The Header</th>
</tr>
</thead>
<tbody>
<tr><td>Item1</td><td>2</td></tr>
<tr><td>Item2</td><td>5</td></tr>
<tr><td>Item3</td><td>3</td></tr>
</tbody>
</table>
</div>
You need to add z-index to the divs, with a positive number for the top div and negative for the div below
example
give css like this
table{position:relative}
And for the Close Button
.closeButton{ position:absolute; top:0; right:0; z-index:999}
You need to change the top and right value according to your requirements
http://jsfiddle.net/Lubuu/5/
Set position:relative; for the close button container.
Set position:absolute for the button.
Set z-index for both (higher index for button).
Use: right: 0; top: 0; for button.
Change the position of .close_box to 'absolute'
Fiddle here: http://jsfiddle.net/9kXmq/
position:absolute;
I have a dynamically generated div.
I have to add a dynamically generated HTML table on it.
The problem is when I'm add the table, it display as left aligned.
But the div is center aligned for text contents.
Assuming you have your table as a fixed width element, you can set margin-left/right to auto to center a block element in it's container. (Fiddle here: http://jsfiddle.net/SWakJ/)
HTML
<div id="div1">
<table id="tab">
<tr>
<td>test</td>
</tr>
</table>
</div>
CSS
#tab {
border:solid 1px black;
width: 200px;
height: 100px;
margin:2px auto;
}
You may try to add some css to your outer div.
I actually wrote a similar answer here:
Position this div in the center of it's container?
Give your code or just go quick to your code and check this. Put a div above table and set text-align= center. or if your table is in any td then assign text-align:center.
Also you can put tag and put table between it.
If you want to just center the table column than also provide text-align:center
I dont know about your code but as per problem this could help you.
function makeTable() {
row=new Array();
cell=new Array();
row_num=12; //edit this value to suit
cell_num=12; //edit this value to suit
tab=document.createElement('table');
tab.setAttribute('id','newtable');
tbo=document.createElement('tbody');
for(c=0;c<row_num;c++){
row[c]=document.createElement('tr');
for(k=0;k<cell_num;k++) {
cell[k]=document.createElement('td');
cont=document.createTextNode((c+1)*(k+1))
cell[k].appendChild(cont);
row[c].appendChild(cell[k]);
}
tbo.appendChild(row[c]);
}
tab.appendChild(tbo);
document.getElementById('mytable').appendChild(tab);
}
the you can set allignment through CSS as below:
#newtable{
border:2px solid #999;
font-family:verdana,arial,helvetica,sans-serif;
font-size:18px;
margin:auto;
}
#newtable td{
width:50px;
line-height:50px;
border:1px solid #000;
text-align:center;
}
or see this link "http://www.webmasterworld.com/javascript/3614377.htm"
You can use like this
<div id="div1">
<table id="tab">
<tr>
<td>test</td>
</tr>
</table>
</div>
CSS
#div1
{
width:500px;
text-align:center;
}
#tab {
border:solid 1px black;
width: 200px;
height: 100px;
margin:2px auto;
}
#tab td
{
/* width: 200px;
text-align:center;*/
}
Running Demo Jsfiddle
Please see the following example:
http://jsfiddle.net/6t6hq/7/
when I use td with position relative to move it,
it only move the content but not the border.
How can I move the border with the content?
<table>
<tr>
<td id="relativeTD">1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
<div id="expected">expected</div>
<style>
td{
border:1px solid #000;
min-width:100px;
}
#relativeTD{
position:relative;
left:60px;
}
#expected{
border:1px solid #000;
position:relative;
left:60px;
}
</style>
TD is of display: table-cell;!
So you can't move it using relative positioning. Instead, create another <div> inside the <td> and give border and stuff.
Instead, give position: absolute for the td. It works! Also, you need to give position: relative to the table.
Fiddle: http://jsfiddle.net/6t6hq/9/
Else, you can use margin-left too to the td.
You cannot move a single td border you need to move the whole table
Demo
table {
margin-left: 60px;
}
Either what you can do is give your table border: 0;, place a div inside your td
give it some width, border and position: relative with left: 60px; and you are good to go