I have some nested tables. There is the main, outer table, it has to nested tables for the left and right columns, and in each column some tables are stacked on top of each other. What I can't seem to figure out is how to get the tables in the column to all span the same width (mostly in the right column). Here is the HTML, scaled down for readability:
<table class="outer">
<tr>
<td>
<table class="column" id="left_column">
<tr>
<td>
<table class="cell" id="t1">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t2" style="margin-top:20px; margin-left:86px">
</table>
</td>
</tr>
</table>
</td>
<td>
<table class="column" id="rightColumn">
<tr>
<td>
<table class="cell" id="t3">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t4">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t5">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t6">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t7">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t8">
</table>
</td>
</tr>
<tr>
<td>
<table class="messages" id="t9">
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
And here is the relevant CSS:
.outer
{
margin: auto;
}
.column
{
border: none;
margin-left: auto;
margin-right: auto;
}
table.cell
{
border-collapse: collapse;
}
#rightColumn table
{
padding: 10px;
width: 100%;
}
Any advice is appreciated.
If you really want to nail down table column widths, use the table-layout: fixed CSS property on the table and specify widths for all of the cells in the first row (or use col elements if you're starting with no first row).
So the CSS I had was valid. Firefox had actually cached an older CSS for this page. The widths went to 100% as soon as I cleared the cache.
Related
I have a page with 3 tables inside, one of which is generated from server data and can have any number of rows. The other 2 tables are used to float on top and display buttons and table headers that can be visible at all times. Here is some code:
<table style=" position:absolute, top: 110px; z-indez:1; width:100%;">
<tr>
<td>
<table>
<tr>
<td> Cart </td>
<td> Quantity </td>
</tr>
</table>
</td>
</tr>
</table>
<table style="margin-top:60px; height:auto; width:100%;">
#foreach (var item in Model) {
<tr>
<td>
#Html.Partial("MoreInformation", item)
</td>
</tr>
}
</table>
<table style="position:absolute; bottom:100px; height:70px; width:100%;">
<tr>
<td>
<table>
<tr>
<td style="text-align:left;">
<button type="button" onclick="window.location.href='/Home/Index'">Go Home</button>
</td>
</tr>
</table>
</td>
</tr>
</table>
There is a problem with this setup:
I have a menu on the left side. When I collapse it, the table with MoreInformation follows is smoothly, but the other 2 tables stay fixed on their positions.
How can I make the "floating on top" tables move along with the data table (the table with MoreInformation?
P.S. I have tried placing the 2 tables inside a div, making that div position:fixed and the table inside position:relative but it does not work.
<table style=" position:absolute, top: 110px; z-indez:1; width:100%;">
<tr>
<td>
<table align="left">
<tr>
<td style="text-align:left;">
<button type="button" onclick="window.location.href='/Home/Index'">Go Home</button>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table>
<tr>
<td> Cart </td>
<td> Quantity </td>
</tr>
</table>
</td>
</tr>
</table>
<table style="margin-top:60px; height:auto; width:100%;">
#foreach (var item in Model) {
<tr>
<td>
#Html.Partial("MoreInformation", item)
</td>
</tr>
}
</table>
I have a scenario where one table had some tr and other table have less tr's than first one table.Both tables are under td's. In this Scenerio how to increase only last tr height of html table in % mode not in px mode
HTML CODE:
<table border="1" style="width:100%">
<tr>
<td style="width:50%">
<table border="1" style="width:100%">
<tr>
<td>
A
</td>
</tr>
<tr>
<td>
B
</td>
</tr>
<tr>
<td>
C
</td>
</tr>
</table>
</td>
<td style="vertical-align:top">
<table border="1" style="width:100%;">
<tr>
<td>
1
</td>
</tr>
<tr>
<td>
2
</td>
</tr>
</table>
</td>
</tr>
jsfiddle Demo
Try like this: Demo This will expand only last row of right side content
CSS:
table {
height: 100%;
width: 100%;
}
td {
}
.table {
display: table;
height:100%;
}
.cell {
vertical-align: top;
display: table-cell;
height:100%;
}
.container {
height: 100%;
-moz-box-sizing: border-box;
}
HTML:
<table border="1" style="width:100%;" class="table">
<tr>
<td>1</td>
</tr>
<tr>
<td>2</td>
</tr>
<tr>
<td class="cell">
<div class="container">Increse this row height till parents td height</div>
</td>
</tr>
</table>
EDIT: If you want right column should be equally expanded, you can use like this: Demo
CSS:
table {
height: 100%;
width: 100%;
}
Hope this is what you want!!
use single table and rowspan
<table border="1" style="width:100%">
<tr><td>A</td><td>1</td></tr>
<tr><td>B</td><td>2</td></tr>
<tr><td>C</td><td rowspan="3">3</td></tr>
<tr><td>D</td></tr>
<tr><td>E</td></tr>
</table>
I'm about to create a table which is going to look like this one right here:
Now it's getting tricky since the website is going to be responsive. That's why I thought it would be nice to wrap the table in a div .cross-tab which has overflow: scroll.
<div class="bs-example">
<div class="cross-tab">
<table>
<thead>
<tr>
<? for ($i=0; $i < 19; $i++) { ?>
<th>
<img src="http://placehold.it/40x40" class="team-icon">
</th>
<? } ?>
</tr>
</thead>
<tbody>
<tr></tr>
</tbody>
</table>
</div>
</div>
The div should have a certain width the overflow: scroll. So the table would be full-sized on any device but get cropped off on small screens with a scrollbar to scroll arround:
Is there a way to accomplish this with pure CSS or do I have to calculate the full table with with js and so on?
You can fix your problem with media query.
For example :
HTML
<body>
<div>
<table border="1" cellspacing="2" cellpadding="0">
<tr> <td> </td> </tr> <tr> <td> </td> </tr>
<tr> <td> </td> </tr> <tr> <td> </td> </tr>
<tr> <td> </td> </tr> <tr> <td> </td> </tr>
<tr> <td> </td> </tr> <tr> <td> </td> </tr>
<tr> <td> </td> </tr> <tr> <td> </td> </tr>
</table>
</div>
</body>
CSS
div
{
background : red;
width:100%;
overflow:auto;
}
table
{
width :100%;
overflow:hidden;
}
#media screen and (max-width: 640px)
{
table
{
width : 800px;
}
div
{
height:200px;
}
}
codepen : http://codepen.io/ColoO/pen/xuACl
I have a very simple problem: I need to center a table inside a TD element. If I were using HTML 4 I'd do it like this:
<table style="border:solid;width: 100%">
<tr>
<td align="center">
<table style="border:solid; width:50%">
<tr>
<td >I must be in the center</td>
</tr>
</table>
</td>
</tr>
</table>
But I'm trying not to use deprecated attributes and do it the CSS way. I already tried this:
<td style="text-align:center">
And this:
<td style="margin: 0 auto">
And the tables keeps in the left-side of the cell. Any suggestions?
You had the right idea with margin:auto 0; just take off the 0.
Working example: http://jsfiddle.net/cxnR8/
<table style="border:solid;width: 100%">
<tr>
<td>
<table style="margin:auto;border:solid; width:50%">
<tr>
<td >I must be in the center</td>
</tr>
</table>
</td>
</tr>
</table>
But, more importantly, do you really need to use tables and in-line styling?
Center the table using the deprecated align="" attribute.
<table>
<tr>
<td>
<table align="center">
<tr>
<td>in the middle</td>
</tr>
</table>
</td>
</tr>
</table>
Your seccond suggestion is correct. See this working example.
HTML:
<table class="outer">
<tr>
<td>
<table class="inner">
<tr>
<td>in the middle</td>
</tr>
</table>
</td>
</tr>
</table>
CSS:
.outer
{
width: 100%;
border: solid 1px red;
}
.inner
{
width: 25%;
margin: auto;
border: solid 1px blue;
}
I have some nested tables where there is one outer, container table, two column tables nested in the outer table, and then various tables stacked on each other in the columns. Here is the relevant HTML:
<table class="outer">
<tr>
<td>
<table class="column" id="left_column">
<tr>
<td>
<table class="cell" id="t1">
<tr><td><asp:Literal runat="server" ID="t1r2c0" /></td><td><asp:Literal runat="server" ID="t1r2c1" /></td><td class="image"><span id="s1" runat="server"><asp:PlaceHolder ID="p1" runat="server"></asp:PlaceHolder></span></td><td><asp:Literal runat="server" ID="t1r2c3" /></td><td class="gray"><asp:Literal runat="server" ID="t1r2c4" /></td></tr>
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t2">
</table>
</td>
</tr>
</table>
</td>
<td>
<table class="column" id="rightColumn">
<tr>
<td>
<table class="cell" id="t3">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t4">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t5">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t6">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t7">
</table>
</td>
</tr>
<tr>
<td>
<table class="cell" id="t8">
</table>
</td>
</tr>
<tr>
<td>
<table class="messages" id="t9">
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
And here is the relevant CSS:
.cell
{
border: none;
}
.cell td
{
border-collapse: collapse;
border: 2px solid black;
text-align: center;
vertical-align: middle;
padding: 2px;
}
.image
{
padding: 0;
margin: 0;
width: 65px;
}
My problem is that the image tds have a padding of 2px. My understanding was that the CSS for .image -- being more specific -- should override the CSS for ".cell td".
Any advice is appreciated.
Specificity isn't determined by how "deep" the elements are, but just by how explicit the selectors are.
The specificity score is based on
the number of ID selectors
otherwise, the number of class/attribute selectors
otherwise, the number of element selectors
.cell td contains a class selector and an element selector
.image contains a class selector and no element selectors
So, the first rule is more specific.