HTML border only outside the table - html

How can I put border only around of my external table? I don't need in every <tr> but just around. I tried to use css but in a Joomla article it is not easy. Thanks for help.
<table style="background-color: #ffffff; filter: alpha(opacity=40); opacity: 0.95;">
<tbody>
<tr>
<td>aasda</td>
<td>asfasf<a title="Ep. 1 Sono Reika"> </a></td>
<td width="60%">asfasfasfasf</td>
<td>blabla</td>
</tr>
<tr>
<td>saf</td>
<td><a title="Ep. 2 La grazia"> </a>asf</td>
<td width='"70%'>asf</td>
<td rowspan="9" width="30%">
<p>blabla</p>
<p>blalbalbalalb</p>
</td>
</tr>
<tr>
<td>asf</td>
<td><a title="Ep. 2 La grazia"> </a>asf</td>
<td>asf</td>
</tr>
<tr>
<td>asf</td>
<td><a title="Ep. 2 La grazia"> </a>asf</td>
<td width='"70%'>asf</td>
</tr>
</tbody>
</table>

You need to add the property border:1px solid red to your table
<table style="background-color: #ffffff; filter: alpha(opacity=40); opacity: 0.95;border:1px red solid;">
<tbody>
<tr>
<td>aasda</td>
<td>asfasf<a title="Ep. 1 Sono Reika"> </a></td>
<td width="60%">asfasfasfasf</td>
<td>blabla</td>
</tr>
<tr>
<td>saf</td>
<td><a title="Ep. 2 La grazia"> </a>asf</td>
<td width='"70%'>asf</td>
<td rowspan="9" width="30%">
<p>blabla</p>
<p>blalbalbalalb</p>
</td>
</tr>
<tr>
<td>asf</td>
<td><a title="Ep. 2 La grazia"> </a>asf</td>
<td>asf</td>
</tr>
<tr>
<td>asf</td>
<td><a title="Ep. 2 La grazia"> </a>asf</td>
<td width='"70%'>asf</td>
</tr>
</tbody>
</table>
<p></p>

Table with border outside
table {
border: 1px solid black;
border-collapse: collapse;
}
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
Table with border outside and in rows
table, tr {
border: 1px solid black;
border-collapse: collapse;
}
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
<td>50</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
<td>94</td>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
<td>80</td>
</tr>
</table>
Could go on and create for all cases but you get the point.
In CSS we specify what we want to have border.
We can do apply it to zero or more of the following elements, depending on what we want the end result to look like
<table> (table)
<tr> (table row)
<td> (table data)
<th> (table heading)

Not sure if I understood correctly, but solution to my problem is
table {
border: 1px solid;
}
instead of any of
table th, table td {
border: 1px solid;
}
that way you will only get an outside border for the table, instead of every row or cell, source: https://www.w3schools.com/css/css_table.asp

Related

Table break in css

When a page is saved as pdf, the table breaks but the bottom border of table on first page and top border of table on second page is not displayed.
I want to get border to bottom and top side of table when it breaks on different pages and saved as pdf.
Here is a simple example
table {
border-collapse: collapse;
}
table,
tr,
td {
border: 1px solid;
}
.page-break {
page-break-after: always;
border-left-color: white;
border-right-color: white;
border-bottom-color: white;
}
.page-break-next-row {
border-left-color: white;
border-right-color: white;
border-top-color: white;
}
<table>
<tr>
<td>row</td>
</tr>
<tr>
<td>row</td>
</tr>
<tr>
<td>row</td>
</tr>
<tr>
<td>row</td>
</tr>
<tr>
<td>row</td>
</tr>
<tr>
<td>row</td>
</tr>
<tr>
<td>row</td>
</tr>
<tr>
<td>row</td>
</tr>
<tr>
<td>row</td>
</tr>
<tr>
<td>row</td>
</tr>
<tr class="page-break">
<td class="page-break">
</td>
</tr>
<tr class="page-break-next-row">
<td class="page-break-next-row"></td>
</tr>
<tr>
<td>row</td>
</tr>
<tr>
<td>row</td>
</tr>
<tr>
<td>row</td>
</tr>
<tr>
<td>row</td>
</tr>
<tr>
<td>row</td>
</tr>
</table>

How can I select the last row of first table in the html code?

<!DOCTYPE html>
<html>
<head>
<style>
table:first-child,
tr:nth-last-child(1) {
border: 1px solid black;
color: #ffff00;
}
</style>
</head>
<body>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
<tr>
<td>John</td>
<td>Wade</td>
</tr>
<tr>
<td>Liam</td>
<td>Mike</td>
</tr>
</table>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
<tr>
<td>John</td>
<td>Wade</td>
</tr>
<tr>
<td>Liam</td>
<td>Mike</td>
</tr>
</table>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
<tr>
<td>John</td>
<td>Wade</td>
</tr>
<tr>
<td>Liam</td>
<td>Mike</td>
</tr>
</table>
</body>
</html>
How can I select all the td elements in the last row of the first table on the webpage?
What happens is the whole table gets affected if I combine it with tr tag using the "," selector but if I code them separately then all the tables last rows get affected.
I just don't know how to combine table and tr correctly
Is this you wanted?
table:nth-child(1) tr:last-child td {
background-color: green;
}
Or:
table:first-child tr:last-child td {
background-color: green;
}
Use table:nth-child(1) for selecting only the first table itself. And then select the last row by tr:nth-last-child(1).
Try this:
table:nth-child(1) tr:nth-last-child(1) {
color: red;
}
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
<tr>
<td>John</td>
<td>Wade</td>
</tr>
<tr>
<td>Liam</td>
<td>Mike</td>
</tr>
</table>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
<tr>
<td>John</td>
<td>Wade</td>
</tr>
<tr>
<td>Liam</td>
<td>Mike</td>
</tr>
</table>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Peter</td>
<td>Griffin</td>
</tr>
<tr>
<td>Lois</td>
<td>Griffin</td>
</tr>
<tr>
<td>John</td>
<td>Wade</td>
</tr>
<tr>
<td>Liam</td>
<td>Mike</td>
</tr>
</table>
/html/body/table[1]/tr[5]
This path represent your last row of first table.Similarly
/html/body/table[2]/tr[5] represents last row of second table.

Separate <tbody> with box-shadow

How to separate tbody with box-shadow from another tbody?
Like a
tbody {
margin-bottom: 16px
}
But, I don't want to use display: block on tbody.
JSFIDDLE:
http://jsfiddle.net/kw9odqjr/1/
IMG what I want:
Instead of repeating tbody many time you can used below structure:
table {
width: 100%;
border-collapse: collapse;
table-layout: fixed;
border: none;
}
tbody table {
box-shadow: 0 0 0 1px black;
border-radius: 8px;
}
<table>
<thead>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan="2">
<table>
<tr>
<td>Jill</td>
<td>Smith</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
</tr>
</table>
</td>
</tr>
<tr><td colspan="2" height="20"></td></tr>
<tr>
<td colspan="2">
<table>
<tr>
<td>Jill</td>
<td>Smith</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
</tr>
</table>
</td>
</tr>
<tr><td colspan="2" height="20"></td></tr>
<tr>
<td colspan="2">
<table>
<tr>
<td>Jill</td>
<td>Smith</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
</tr>
</table>
</td>
</tr>
<tr><td colspan="2" height="20"></td></tr>
</tbody>
</table>
It's not allowed to assign margin for tbody,
you can insert a separator like this
<tbody style="box-shadow:none; height:20px;">
<tr></tr>
</tbody>

Highlight whole row regardless rowpsan - css

I have the code below:
tbody > tr:hover{
background-color: lightgrey;
cursor: pointer;
}
<table border="1">
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
<th>Savings for holiday!</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">January</td>
<td>Week 1</td>
<td >$150</td>
</tr>
<tr>
<td>Week 3</td>
<td>$100</td>
</tr>
<tr>
<td rowspan="2">February</td>
<td>Week 2</td>
<td >$50</td>
</tr>
<tr>
<td>Week 1</td>
<td>$80</td>
</tr>
</tbody>
</table>
How can I highlight the whole row when I hover to the row.
For example, when I hover to January, it should highlight the whole January row instead of highlight only the half one because of the rowspan attribute.
Move the styling to the td under the hovered tr. In addition, highlight the sibling row, when the 1st row is hovered. The only caveat is that if the 2nd tr is hovered, it won't highlight the 1st cell.
tr:hover > td {
background-color: lightgrey;
cursor: pointer;
}
tr:nth-child(2n + 1):hover + tr {
background-color: lightgrey;
}
<table border="1">
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
<th>Savings for holiday!</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">January</td>
<td>Week 1</td>
<td>$150</td>
</tr>
<tr>
<td>Week 3</td>
<td>$100</td>
</tr>
<tr>
<td rowspan="2">February</td>
<td>Week 2</td>
<td>$50</td>
</tr>
<tr>
<td>Week 1</td>
<td>$80</td>
</tr>
</tbody>
</table>
tr:hover td:not([rowspan]) {background: red;}
tr:hover td[rowspan]:hover ~ td {background: none;}
tr:hover td[rowspan]:hover {background: yellow;}
<table border="1">
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
<th>Savings for holiday!</th>
</tr>
</thead>
<tbody>
<tr>
<td rowspan="2">January</td>
<td>Week 1</td>
<td >$150</td>
</tr>
<tr>
<td>Week 3</td>
<td>$100</td>
</tr>
<tr>
<td rowspan="2">February</td>
<td>Week 2</td>
<td >$50</td>
</tr>
<tr>
<td>Week 1</td>
<td>$80</td>
</tr>
</tbody>
</table>

Why am I able to change the border color and thickness of my table' <thead> , but not the background color?

I am able to change the border styling of the top bar in the table, but I can't it to change the background color no matter what I do. Can anyone tell me where I am going wrong? My code is below:
<table>
<thead>
<tr >
<th>strong>Colour</strong></th>
<th><strong>Red</strong></th>
<th><strong>Green</strong></th>
<th><strong>White</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Length (m)</td>
<td>1</td>
<td>0.5</td>
<td>0.5</td>
</tr>
<tr>
<td align="left">Weight (kg)</td>
<td>4</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td align="left">Burn Time (sec)</td>
<td>60</td>
<td>22</td>
<td>15</td>
</tr>
<tr>
<td align="left">Light Output (cd)</td>
<td>200 000</td>
<td>100 000</td>
<td>850 000</td>
</tr>
<tr>
<td align="left">Visibility at sea level (km)</td>
<td>20</td>
<td>15</td>
<td>26</td>
</tr>
</tbody>
CSS:
table th, table td {
border: 1px solid gray;
}
table thead td, table thead tr {
background-color: pink;
border: 4px solid pink;
}
Your html code has some syntax erros:
Corrected here and working well:
<html>
<head>
<link rel="stylesheet" href="style.css">
<script src="script.js"></script>
</head>
<body>
<table>
<thead>
<tr >
<th><strong>Colour</strong></th>
<th><strong>Red</strong></th>
<th><strong>Green</strong></th>
<th><strong>White</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Length (m)</td>
<td>1</td>
<td>0.5</td>
<td>0.5</td>
</tr>
<tr>
<td align="left">Weight (kg)</td>
<td>4</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td align="left">Burn Time (sec)</td>
<td>60</td>
<td>22</td>
<td>15</td>
</tr>
<tr>
<td align="left">Light Output (cd)</td>
<td>200 000</td>
<td>100 000</td>
<td>850 000</td>
</tr>
<tr>
<td align="left">Visibility at sea level (km)</td>
<td>20</td>
<td>15</td>
<td>26</td>
</tr>
</tbody>
</table>
</html>
http://plnkr.co/edit/XnLr3Fw9MO7jwvJrfjgB?p=preview
It's working for me! Take care with the tags... <strong>
table th, table td {
border: 1px solid gray;
}
table thead td, table thead tr {
background-color: pink;
border: 4px solid pink;
}
<table>
<thead>
<tr >
<th><strong>Colour</strong></th>
<th><strong>Red</strong></th>
<th><strong>Green</strong></th>
<th><strong>White</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Length (m)</td>
<td>1</td>
<td>0.5</td>
<td>0.5</td>
</tr>
<tr>
<td align="left">Weight (kg)</td>
<td>4</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td align="left">Burn Time (sec)</td>
<td>60</td>
<td>22</td>
<td>15</td>
</tr>
<tr>
<td align="left">Light Output (cd)</td>
<td>200 000</td>
<td>100 000</td>
<td>850 000</td>
</tr>
<tr>
<td align="left">Visibility at sea level (km)</td>
<td>20</td>
<td>15</td>
<td>26</td>
</tr>
</table>
Your CSS should include one more rule, for the <th> tag:
table th, table td {
border: 1px solid gray;
}
table thead td, table thead tr, table thead th {
background-color: pink;
border: 4px solid pink;
}
Also, you have error in the HTML code - missing starting bracket in <strong> tag on line <th>strong>Colour</strong></th>.
Check out the working fiddle.
Try like this: Demo
Instead of giving border for tr you can give for td and th
table thead td, table thead tr th { /* added th after tr */
background-color: pink;
border: 4px solid pink;
}
And try to open and close tags properly to get expected output :)
No need to add so many styles. Apply this.
table th, table thead tr td {
border: 1px solid red;
}
table thead tr {
background-color: red;
border: 4px solid pink;
}
<table>
<thead>
<tr >
<th><strong>Colour</strong></th>
<th><strong>Red</strong></th>
<th><strong>Green</strong></th>
<th><strong>White</strong></th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Length (m)</td>
<td>1</td>
<td>0.5</td>
<td>0.5</td>
</tr>
<tr>
<td align="left">Weight (kg)</td>
<td>4</td>
<td>2</td>
<td>2</td>
</tr>
<tr>
<td align="left">Burn Time (sec)</td>
<td>60</td>
<td>22</td>
<td>15</td>
</tr>
<tr>
<td align="left">Light Output (cd)</td>
<td>200 000</td>
<td>100 000</td>
<td>850 000</td>
</tr>
<tr>
<td align="left">Visibility at sea level (km)</td>
<td>20</td>
<td>15</td>
<td>26</td>
</tr>
</tbody>