Remove borders in nested table - html

How does one prevent the inheriting of borders in a nested tabled?
I tried to a add a borderless class to the nested table, but the borders of the parent class are still inherited.
.plain_tbl {
border: none;
}
.plain_tbl tr td {
border: none;
}
.tbl {
border: 1px solid;
}
.tbl tr td {
border: 1px solid;
}
<table class="tbl">
<tr>
<td align=center style="padding:50px">
<table border=0 class="plain_tbl">
<tr>
<td>0--------------------100</td>
</tr>
<tr>
<td align=center> ^ <br>50</td>
</tr>
</table>
</td>
</tr>
</table>
I am looking for a solution which does not change the parent class, i.e. how to make the nested class overwrite the parent class

The problem you have is
.tbl tr td {
border: 1px solid;
}
which will add a border to every <td> also if it is a table inside a table you could fix it by using
.tbl > tr > td {
border: 1px solid;
}
.plain_tbl {
border: none;
}
.plain_tbl tr td {
border: none;
}
.tbl {
border:1px solid;
}
.tbl > tr > td {
border: 1px solid;
}
<table class="tbl">
<tr>
<td align=center style="padding:50px">
<table border=0 class="plain_tbl">
<tr><td>0--------------------100</td></tr>
<tr><td align=center> ^ <br>50</td></tr>
</table>
</td>
</tr>
</table>
Update, another solution then previous using specificity
In the comments you asked
why does the nested class not overwrite the parent class?
The reason is Specificity and the order of your CSS rules. If you are not allowed to change the CSS order you can change the specificity. You need to be more specific then this
.tbl tr td {
border: 1px solid;
}
To be more specific you can change like so
.tbl .plain_tbl tr td {
border: none;
}
run the code snippet and see it work
.plain_tbl {
border: none;
}
.tbl .plain_tbl tr td {
border: none;
}
.plain_tbl tr td {
border: none;
}
.tbl {
border:1px solid;
}
.tbl tr td {
border: 1px solid;
}
<table class="tbl">
<tr>
<td align=center style="padding:50px">
<table border=0 class="plain_tbl">
<tr><td>0--------------------100</td></tr>
<tr><td align=center> ^ <br>50</td></tr>
</table>
</td>
</tr>
</table>
Third method, only changing the order of your css
because both rules actually have the same specificity you can also just place the rule .plain_tbl tr td after .tbl tr td { in your css file like so:
.plain_tbl {
border: none;
}
/*
move this to the bottom
.plain_tbl tr td {
border: none;
}
*/
.tbl {
border: 1px solid;
}
.tbl tr td {
border: 1px solid;
}
/* see here */
.plain_tbl tr td {
border: none;
}
<table class="tbl">
<tr>
<td align=center style="padding:50px">
<table border=0 class="plain_tbl">
<tr><td>0--------------------100</td></tr>
<tr><td align=center> ^ <br>50</td></tr>
</table>
</td>
</tr>
</table>

your problem lies with the order of rules, since .tbl td is more general, it also applied to the inner element, and since its the last rule applied, it overrides the previous rule, which is the more specific rule
.
so simply rearrange your css and fix
.tbl {
border: 1px solid;
}
.tbl tr td {
border: 1px solid;
}
.plain_tbl {
border: none;
}
.plain_tbl tr td {
border: none;
}
<table class="tbl">
<tr>
<td align=center style="padding:50px">
<table border=0 class="plain_tbl">
<tr>
<td>0--------------------100</td>
</tr>
<tr>
<td align=center> ^ <br>50</td>
</tr>
</table>
</td>
</tr>
</table>

You can f.e. remove the plain_tbl class completely, and just apply the border to table cells that are in rows that are direct descendants of your main table:
.tbl,
.tbl > tr > td {
border: 1px solid;
}

Related

Remove table border

I want to remove the following border but I do not know how to do it.
How would I be able accomplish to remove this using CSS? Please help me out, it's very much appriciated!
My HTML and CSS below:
table {
width:100%;
font-size:14px;
}
table, th, td {
border: 1px solid #00b0f0;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
table tr:nth-child(even) {
background-color: rgba(0, 176, 240, 0.1);
}
table tr:nth-child(odd) {
background-color:#fff;
}
table th {
background-color:#00b0f0;
color: white;
}
<table>
<tr>
<th>IP</th>
<th>Datum</th>
</tr>
<tr>
<td>::1</td>
<td>8-5-2016
</td>
<td>
<a href="index.php?page=bruteforce&action=verwijderitem&id=1">
<img src="assets/images/icons/2.gif" class="iconbtn" alt="Verwijder" title="Verwijder" />
</a>
</td>
</tr>
</table>
You need to remove the border from the left side of the last div and right side of the previous div.
So I have added two classes .no-left-border and .no-right-border and applied them to the applicable td tags.
table {
width: 100%;
font-size: 14px;
}
table,
th,
td {
border: 1px solid #00b0f0;
border-collapse: collapse;
}
th,
td {
padding: 5px;
text-align: left;
}
table tr:nth-child(even) {
background-color: rgba(0, 176, 240, 0.1);
}
table tr:nth-child(odd) {
background-color: #fff;
}
table th {
background-color: #00b0f0;
color: white;
}
.no-border-right {
border-right: none;
}
.no-border-left {
border-left: none;
}
<table>
<tr>
<th>IP</th>
<th>Datum</th>
</tr>
<tr>
<td>::1</td>
<td class="no-border-right">8-5-2016</td>
<td class="no-border-left">
<a href="index.php?page=bruteforce&action=verwijderitem&id=1">
<img src="assets/images/icons/2.gif" class="iconbtn" alt="Verwijder" title="Verwijder" />
</a>
</td>
</tr>
</table>
Remove the left border from the last TD :nth-last-child(1){
Remove the right border from the penultimate TD :nth-last-child(2){
table {
width:100%;
font-size:14px;
}
table, th, td {
border: 1px solid #00b0f0;
border-collapse: collapse;
}
th, td {
padding: 5px;
text-align: left;
}
table tr:nth-child(even) {
background-color: rgba(0, 176, 240, 0.1);
}
table tr:nth-child(odd) {
background-color:#fff;
}
table th {
background-color:#00b0f0;
color: white;
}
table tr td:nth-last-child(1){ /* LAST TD */
border-left: none;
}
table tr td:nth-last-child(2){ /* PENULTIMATE TD */
border-right: none;
}
<table>
<tr>
<th>IP</th>
<th>Datum</th>
</tr>
<tr>
<td>::1</td>
<td>8-5-2016
</td>
<td>
<a href="index.php?page=bruteforce&action=verwijderitem&id=1">
<img src="assets/images/icons/2.gif" class="iconbtn" alt="Verwijder" title="Verwijder" />
</a>
</td>
</tr>
</table>
Due to border collapse, even if you see 1px border there's actually two overlapping borders, so you have to remove both borders accordingly to achieve the needed result (no border).
Working code & preview
<html>
<head>
<style>
body,th,td
{
font-family:Arial,Helvitica,Sans;
font-size:13px;
}
table
{ border-spacing:0; }
th
{
background:#00b0f0;
color:#FFF;
border: 1px solid #00b0f0;
padding:0.4em;
text-align:left;
}
td
{
min-width:70px;
background:#e6f7fe;
border: 1px solid #00b0f0;
padding:0.8em;
}
.blank
{
background:none;
border:none;
}
.no-line-l
{ border-left:none; }
.no-line-r
{ border-right:none; }
.the-x
{
font-weight:bold;
text-align:right;
color:#A00;
}
</style>
</head>
<body>
<table>
<tr>
<th>IP</th>
<th>Datum</th>
<th class="blank"></th>
</tr>
<tr>
<td class="no-line-r">::1</td>
<td class="no-line-r">8-5-2016</td>
<td class="no-line-l the-x">X</td>
</tr>
</table>
</body>
</html>
Preview

nth-child code doesn't work

body {
background-color: grey;
}
table {
width: 100%;
}
th, td, tr {
border-collapse: collapse;
}
th {
border: 3px solid black;
background-color: #F2F2F2
}
td {
border: 1px solid black;
}
tr:nth-child(odd) {
background-color: #ff0000
color: black
}
tr:nth-child(odd) {
background-color: #00ffff
color: white
}
I've tried a hundred ways of rewriting this but I can't for the life of me get the 'nth-child' bits to work. I'm simply trying to alternate the table row colors. Any help in advance is appreciated.
You need to put the backgrounds on the columns, not the rows.
tr:nth-child(odd) td {}
tr:nth-child(even) td {}
Will be sufficient to achieve what you want.
Here's a jsFiddle achieving what you want
CSS
<style type="text/css">
body {
background-color: grey;
}
table {
width: 100%;
}
th, td, tr {
border-collapse: collapse;
}
th {
border: 3px solid black;
background-color: #F2F2F2;
}
td {
border: 1px solid black;
}
tr:nth-child(odd) td {
background-color: #ff0000;
color: black;
}
tr:nth-child(even) td {
background-color: #00ffff;
color: white;
}
</style>
EG: HTML
<table width="100%" border="1" cellspacing="0" cellpadding="0">
<tr>
<th> Head 1</th>
<th> Head 2</th>
</tr>
<tr>
<td> Content 1.1</th>
<td> Content 1.2</td>
</tr>
<tr>
<td> Content 2.1</th>
<td> Content 3.2</td>
</tr>
<tr>
<td> Content 3.1</th>
<td> Content 3.2</td>
</tr>
<tr>
<td> Content 4.1</th>
<td> Content 4.2</td>
</tr>
</table>
Result
You need to use it.
<style type="text/css">
tr:nth-child(odd) td {
background-color: #ff0000;
color: black;
}
tr:nth-child(even) td {
background-color: #00ffff;
color: white;
}
</style>

CSS Child selector not working as expected

I have an HTML table with another table embedded in it like:
table.index {
border-radius: 10px;
border: solid 1px #61a2d1;
border-spacing: 0;
}
table.index > thead > tr:first-child {
background-color: #61a2d1;
}
table.index > thead > tr:first-child > td:first-child {
border-top-left-radius: 10px;
}
table.index > thead > tr:first-child > td:last-child {
border-top-right-radius: 10px;
}
table.index > thead td {
font-weight: bold;
text-align: center;
}
table.index > tr:nth-child(3) {
background-color: rgba(97, 162, 209, 0.5);
}
table.index > tr:hover {
background-color: #ffda6d;
}
table.index > tbody > tr:last-child td:first-child {
border-bottom-left-radius: 10px;
}
table.index > tbody > tr:last-child td:last-child {
border-bottom-right-radius: 10px;
}
table.index .no-right-borrder {
border-right: none;
}
table.index .no-left-border {
border-left: none;
text-align: right;
}
table.details {
margin: 0;
padding: 0;
border: solid 1px #61a2d1;
border-spacing: 0;
}
<table class="index" style="width:100%">
<thead>
<tr>
<td style="width:2%"></td>
<td></td>
<td></td>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<td class="no-right-borrder" style="vertical-align:middle"><span class="fa fa-caret-right fa-lg"></span></td>
<td class="no-left-border" style="text-align:left;"></td>
<td class="no-right-borrder" style="text-align:center"></td>
<td class="no-left-border"></td>
</tr>
<tr>
<td colspan="4" style="padding:0;margin:0">
<table class="details" style="width:100%">
<tbody>
<tr>
<td colspan="2"><label for=""></label></td>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><label for=""></label></td>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><label for=""></label></td>
<td colspan="2"></td>
</tr>
<tr>
<td colspan="2"><label for=""></label></td>
<td colspan="2"></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
When I open this page, the cells in the table with the class details have rounded corners just like the cells in the table with the class index.
I've used the direct child selector to indicate that I only wanted the routed borders to be applied to direct children of a table with the index class, so I'm not sure why it's happening. When I examine the DOM in Google Developer Tools, it tells me that the border-radius attribute is coming from the .index class. What do I need to do to stop that from happening?
edit: This is what I'm seeing on my local machine. CSS code is copied exactly from my code. Table was simplified because it's auto-generated, but the classes are applied identically.
I suspect you need to change table.index > tbody > tr:last-child td:first-child into table.index > tbody > tr:last-child > td:first-child (putting the direct descendant selector between tr > td), and the same for the td:last-child selector that directly follows.

Styling a table in html

I am new in CSS.I have a Table Like this
<table id="datatable">
<tbody>
<tr>
<td><strong>2013</strong></td>
<td> </td>
<td><strong>144</strong></td>
</tr>
<tr>
<td><strong>2012</strong></td>
<td> </td>
<td><strong>159</strong></td>
</tr>
<tr>
<td><strong>2011</strong></td>
<td> </td>
<td><strong>147</strong></td>
</tr>
<tr>
<td><strong>2010</strong></td>
<td> </td>
<td><strong>137</strong></td>
</tr>
<tr>
<td><strong>2009</strong></td>
<td> </td>
<td><strong>303</strong></td>
</tr>
And I need to style this table as shown below.I have tried something but I can't able to style like that
I just tried
.datatable td {
border-bottom: 1px solid black;
}
Based on the image below,I need first td border as green and others are black.
Can any one help?Thanks in advance for help.
In your code, datatable is an ID not a class. Update your CSS like below.
#datatable tr:first-child td{
border-bottom:1px solid green;
}
#datatable tr td{
border-bottom:1px solid black;
}
#datatable
{
border-collapse:collapse;
}
DEMO
try this one
<table class="datatable">
<tbody>
<tr>
<td ><strong>2013</strong></td>
<td> </td>
<td><strong>144</strong></td>
</tr>
<tr>
<td><strong>2012</strong></td>
<td> </td>
<td><strong>159</strong></td>
</tr>
<tr>
<td><strong>2011</strong></td>
<td> </td>
<td><strong>147</strong></td>
</tr>
<tr>
<td><strong>2010</strong></td>
<td> </td>
<td><strong>137</strong></td>
</tr>
<tr>
<td><strong>2009</strong></td>
<td> </td>
<td><strong>303</strong></td>
</tr>
</table>
In css
.datatable td{
border-bottom:1px solid black;
}
.datatable
{
border-collapse:collapse;
}
.datatable tr:first-child td{
color:green;
border-bottom:1px solid green;
}
You can see it from here
http://jsfiddle.net/ZKv68/2/
use this css
DEMO
.green {
color: green;
}
#datatable td {
border-bottom: 1px solid black;
}
#datatable {
border-collapse: collapse;
}
look here
#datatable{
border-collapse:collapse;
}
#datatable td{
padding-left:4px;
padding-right:4px;
}
#datatable tr{
color:#444444;
border-bottom:2px solid #999999;
}
#datatable tr:first-child{
color:green;
}
. represents class..# represents id...so, change .database to #database in css.
try this:
<tr class=green>
<td><strong>2013</strong></td>
<td> </td>
<td><strong>144</strong></td>
</tr>
<tr class=black>
<td><strong>2012</strong></td>
<td> </td>
<td><strong>159</strong></td>
</tr>
and in css:
#datatable tr.green {
border-bottom: 1px solid green;
}
#datatable tr.black {
border-bottom: 1px solid black;
}
Add following CSS in your styles
#datatable{
border-collapse: collapse;
}
#datatable td{
border-bottom:1px solid black;
color:#000;
}
#datatable tbody tr:first-child td{
color:#00FF00;
}
here is a live example
http://jsfiddle.net/Ycyyn/
You have a mistake in your CSS. Use #datatable instead of .datatable.
Apply a class or ID to your first row and use something like:
<tr class="green">
<td><strong>2013</strong></td>
<td> </td>
<td><strong>144</strong></td>
</tr>
CSS:
.green{
color:green;
}
You can also use
table tr:first-child {
color:green;
}
instead
If you are using id, then you need to use # to reference it in CSS. Dot is for class.
To reference just the first row, you can use 'first-child'
Example:
#datatable td{
border-bottom:1px solid black;
}
#datatable tr:first-child td {
border-bottom:1px solid green;
}
First of all <table id="datatable"> here you declare an ID and in your CSS .datatable td a class. You have to use # for selecting IDs
Just add this CSS:
#datatable tr:first-child td{
border-bottom:1px solid green;
color:green;
}
#datatable td{
border-bottom:1px solid black;
}
#datatable {
border-collapse: collapse;
}
DEMO

Table Cells lose border in Google Chrome PC

The following code, in all browsers - apart from Google Chrome Latest on the PC - displays a border on the tbody table cells, as specified in the CSS.
Chrome PC, displays the thead border, but not the TD borders. Why? Is it a bug in Chrome, or in my HTML/CSS?
Heres a jsFiddle that replicates it:
<table width="505" cellspacing="0" cellpadding="0" border="0">
<tbody>
<tr>
<td>Testing</td>
<td>123</td>
</tr>
<tr>
<td>Testing</td>
<td>456</td>
</tr>
</tbody>
<thead>
<tr>
<th>foo</th>
<th>bar</th>
</tr>
</thead>
table {
width:736px;
border-collapse: collapse;
thead {
border-top: 2px solid #aaaaaa;
tr {
th {
border: 0;
padding: 12px 5px;
}
}
}
tbody {
border-top:0;
tr {
td {
padding: 10px 5px;
border-top: 1px solid #aaaaaa;
border-bottom: 1px solid #aaaaaa;
}
}
Try with putting tbody after thead.
HTML
<table width="505" cellspacing="0" cellpadding="0" border="0">
<thead>
<tr>
<th>foo</th>
<th>bar</th>
</tr>
</thead>
<tbody>
<tr>
<td>Testing</td>
<td>123</td>
</tr>
<tr>
<td>Testing</td>
<td>456</td>
</tr>
</tbody>
</table>
JSFiddle
From MDN:
thead - A table element. The thead must appear after any caption or colgroup element, even implicitly defined, but before any tbody, tfoot and tr element.
Remove border-collapse: collapse and use border-top for TD and border-bottom for TABLE.
Live demo
Try this.
table {
width:736px;
border-collapse: collapse;
}
thead {
border-top: 2px solid #aaaaaa;
}
th {
border: 0;
padding: 12px 5px;
}
tbody {
border-top:0;
}
td {
padding: 10px 5px;
border-top: 1px solid #aaaaaa;
border-bottom: 1px solid #aaaaaa;
}
I had a table using -webkit-backface-visibility:hidden;, which was hiding border color, so to fix I used -webkit-backface-visibility:visible;.