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.
Related
I've been trying to mimic the following table layout using HTML/CSS:
NOTE: It's a table from LibreOffice Writer which I modified using Gimp to show you what I mean.
As you can see, I'd like to add some left padding to some rows to show visually that they are inside a group.
I tried using padding-left of both <td> and <tr>, and a little trick that don't work: applying 'border-left: 14px solid white' to the <tr> and then 'border-left: 15px solid black' to the first <td> in the row. I thought that the border in the <td> would overlap the <tr> border by 1px, but HTML rendering seems not to work that way :)
Also, I tried to do this:
<tr>
<td colspan="9">
GROUP 1
</td>
</tr>
<tr>
<td colspan="9" style="padding-left: 15px">
<table>
<tr>
<td> <!-- # --> </td>
<td> <!-- Id --> </td>
<td> <!-- Field1 --> </td>
(ETC)
<td> <!-- Comment --> </td>
</tr>
</table>
</td>
</tr>
The problem with this approach is that the column lines of the inside the 'group' don't match the ones that are outside so it doesn't look good...
Any suggestion?
Try this. Remove borders from table cells, instead add divs within each table cell with the border:
<tr>
<td colspan="4">
<div class="cell">GROUP 1</div>
</td>
</tr>
<tr>
<td style="padding-left: 15px">
<div class="cell"> col 1</div>
</td>
<td>
<div class="cell"> col 2</div>
</td>
<td>
<div class="cell"> col 3</div>
</td>
<td>
<div class="cell"> col 4</div>
</td>
</tr>
CSS:
div.cell {
border-left: 1px solid #000;
border-right: none;
border-bottom: none;
}
table {
border-collapse: collapse;
border-right: 1px solid #000;
border-bottom: 1px solid #000;
}
table td {
padding: 0;
border-top: 1px solid #000;
border-bottom: 1px solid #000;
}
See example here: https://codepen.io/anon/pen/baMdWP
Suggestion:
.with-padding {
margin-left: 10px;
}
<table class="normal">
...
</table>
<table class="with-padding">
...
</table>
<table class="normal">
...
</table>
Assign padding-left: 15px to every sub-sequent <tr> that is to be displayed as part of the group. It's better to use a class instead of applying inline style.
Try this way.
HTML
<table style="width:100%">
<tr>
<td style="width:25%;">January</td>
<td style="width:25%;">$100</td>
<td style="width:25%;">January</td>
<td style="width:25%;">$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
<td>February</td>
<td>$80</td>
</tr>
<td colspan="9">
GROUP 1
</td>
</table>
<table style="width:95%;margin-left:5%">
<tr>
<td style="width:20%;">January</td>
<td style="width:25%;">$100</td>
<td style="width:25%;">January</td>
<td style="width:25%;">$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
<td>February</td>
<td>$80</td>
</tr>
</table>
<table style="width:100%">
<tr>
<td style="width:25%;">January</td>
<td style="width:25%;">$100</td>
<td style="width:25%;">January</td>
<td style="width:25%;">$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
<td>February</td>
<td>$80</td>
</tr>
</table>
CSS
table,th,td {
border: 1px solid black;
}
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 trying to merge tables together by using colspan, but cant seem to create my table. How can i merge tables columns together like following:
The general layout would be:
table,
td {
border: 1px solid #000;
}
table {
width: 50%;
border-collapse: collapse;
}
<table>
<tr>
<td rowspan="2"> </td>
<td rowspan="2"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
Here is the solution
HTML code is here:
<table width="500" border="1" cellpadding="0" cellspacing="0">
<tr>
<td rowspan="2"> </td>
<td rowspan="2"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
CSS code is here :
table,td {
border-collapse: collapse;
}
JS fiddle Link : http://jsfiddle.net/naveenkumarpg/543c3896/
if you need exact widths for td's you have to use class selector and adjust accordingly
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. 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.