I need to create an invoice with HTML table, td, tr.
I need something like this
that every item in the invoice is in a new row, but a row without border.
I have tried to add a class for tr element
border: 0px solid black;
but it is not working properly. Can you advise please?
In this snippet is created a table, but there are borders everywhere
<!DOCTYPE html>
<html>
<head>
<style>
thead {color:green;}
tbody {color:blue;}
tfoot {color:red;}
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
</table>
</body>
</html>
Use Border style in CSS like below to remove Border of <tr> <td> in Table.
border-right:none;
border-left:none;
border-bottom:none;
border-top:none
Is it solved ?
Set border for table but for cells you have to specify a custom class to each cell according to its position. I suggest 4 kinds of borders on top, right,bootm and left. Also do not forget to set border-collapse for table to collapse TD borders on each others:
table {
border:1px solid #000000;
border-collapse:collapse;
}
td{
padding:10px;
}
.tB{
border-top:1px solid #000000
}
.rB{
border-right:1px solid #000000
}
.bB{
border-bottom:1px solid #000000
}
.lB{
border-left:1px solid #000000
}
<table>
<tr>
<td class="rB">test</td>
<td class="bB">test</td>
</tr>
<tr>
<td class="rB bB">test</td>
<td class="bB">test</td>
</tr>
</table>
You can use a specific class with style property border:0 to remove the borders form individual row.
Find the solution (on top of your snippet) below:-
tr.noBorder td {
border: 0;
}
tr.noBorder td:first-child {
border-right: 1px solid;
}
<!DOCTYPE html>
<html>
<head>
<style>
thead {color:green;}
tbody {color:blue;}
tfoot {color:red;}
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>
<table>
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tfoot>
<tr>
<td>Sum</td>
<td>$180</td>
</tr>
</tfoot>
<tbody>
<tr class="noBorder">
<td>January</td>
<td>$100</td>
</tr>
<tr class="noBorder">
<td>February</td>
<td>$80</td>
</tr>
</tbody>
</table>
</body>
</html>
Related
I have an html Document with CSS and try the following:
I want to have an Background-Image in <Thead>. This Image should be in the Background of the other td´s. Maybe an overlay?
I want to get the following solution (Note: The Image must be in the thead. The other Td must be without an Background-Image)
Why should I need it?
We are using an online-built-in-software that converts html outputs in pdf. And the thead is the only markup that repeats on every page. Other solutions for repeating a header doesn't work.
A Background-Image at TBody doesn't work for me, because it doesn't repeat when the pagebrake come.
Edit: Update with codes and clearify my question
So Here is a simple code where I start (Thanks to #NickVU)
<style type="text/css">
table, th, td {
border: 1px solid black;
border-collapse: collapse;
width: 500px;
height: 200px;
color: yellow
}
thead {
background-image: url("https://www.w3schools.com/css/img_5terre.jpg");
}
</style>
<table>
<thead>
<tr>
<th>Month</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
</tr>
<tr>
<td>February</td>
</tr>
</tbody>
</table>
So at the End, i want to get the following output. (Like the img. above)
<style type="text/css">
table, th, td {
border: 1px solid black;
border-collapse: collapse;
width: 500px;
height: 200px;
color: yellow
}
table {
background-image: url("https://www.w3schools.com/css/img_5terre.jpg");
background-repeat: no-repeat;
}
</style>
<table>
<thead>
<tr>
<th>Month</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
</tr>
<tr>
<td>February</td>
</tr>
</tbody>
</table>
Note: But the img must be linked at the thead
UPDATED
According your requirement update, now I briefly understood your case.
That's impossible to have background-image with overflow, BUT we can do it with pseudoelement ::before on thead. Here is an example
table,
th,
td {
border: 1px solid black;
border-collapse: collapse;
width: 500px;
height: 200px;
color: white;
position: relative;
}
thead::before {
content: '';
position: absolute;
top: 0;
width: 100%;
height: 100%;
background-image: url("https://www.w3schools.com/css/img_5terre.jpg");
background-repeat: no-repeat;
}
<table>
<thead>
<tr>
<th>Month</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
</tr>
<tr>
<td>February</td>
</tr>
</tbody>
</table>
OLD ANSWER
I think you just simply put it in your CSS
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
thead, tbody {
background-image: url("https://www.w3schools.com/cssref/paper.gif");
}
<table>
<thead>
<tr>
<th>Month</th>
<th>Savings</th>
</tr>
</thead>
<tbody>
<tr>
<td>January</td>
<td>$100</td>
</tr>
<tr>
<td>February</td>
<td>$80</td>
</tr>
</tbody>
</table>
P/s: I'm using W3 school image for the demo. You can replace it with your own image.
What is the easiest way to get such table as bellow in HTML 5. I have a feeling that my solution (with setting style for every td) is not the best way.
<table style="border-collapse: collapse; border: 1px solid;">
<tr>
<td style="border: 1px solid;">1</td>
<td style="border: 1px solid;">2</td>
</tr>
<tr>
<td style="border: 1px solid;">3</td>
<td style="border: 1px solid;">4</td>
</tr>
</table>
What you are trying to do is best accomplished by using an internal CSS stylesheet, rather than using inline styles on your table elements. Following is an example of how you can use a CSS stylesheet to style your table.
First, give the table an id like this:
<table id="thetable" border="1">
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
Then use CSS on the table:
#thetable {
border-collapse: collapse;
border: 1px solid;
}
#thetable td {
border: 1px solid;
}
The entire HTML document would look something like this:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Table Page</title>
<style>
#thetable {
border-collapse: collapse;
border: 1px solid;
}
#thetable td {
border: 1px solid;
}
</style>
</head>
<body>
<table id="thetable" border="1">
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
</body>
</html>
Here is a tutorial on how to get the CSS into your HTML using a stylesheet. Good luck!
Use CSS classes.
table.MyClass {
/* Whatever table styles here */
border-collapse: collapse;
border: 1px solid;
}
table.MyClass td {
/* Whatever cell styles within the table here */
border: 1px solid;
}
<table class="MyClass">
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
Externalise the CSS to a separate stylesheet.
table {
border-collapse: collapse;
border: 1px solid;
}
td {
border: 1px solid red;
}
<table>
<tr>
<td>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td>4</td>
</tr>
</table>
I have a little trouble with changing one tr border color
My table is something like this
<table>
<div id="one">
<tr>
<td></td>
<td></td>
</tr>
</div>
<div id="two">
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</div>
</table>
I would like first <tr><td></td><td></td></tr> to be white and the second one to be blue
I have tried with
#one td, #one tr,#onetable{
border: 1px solid white;
border-color:#ff0000;
But it didn't work
<style type="text/css">
table {
border-collapse: collapse;
}
#one td {
border: 1px solid #ff0000;
}
</style>
<table>
<tr id="one">
<td></td>
<td></td>
</tr>
<tr id="two">
<td></td>
<td></td>
</tr>
</table>
<style type="text/css">
#one td {
border: 1px solid #ff0000;
}
</style>
<table>
<tr id="one">
<td></td>
<td></td>
</tr>
<tr id="two">
<td></td>
<td></td>
</tr>
</table>
http://jsfiddle.net/VCA9Q/
Here you go
<html>
<head>
<style>
body {background-color: beige;}
table {border-collapse: separate;}
table td { width: 50px; height: 50px;}
table tr:first-child td {border: 1px solid #fff; }
table tr:last-child td {border: 1px solid #0000FF; }
</style>
</head>
<body>
<table>
<tr>
<td></td><td></td><td></td>
</tr>
<tr>
<td></td><td></td><td></td>
</tr>
</table>
</body>
</html>
and a fiddle
(btw #0000FF is blue)
If you want to zebra-stripe your table:
table td {
border-width: 1px;
border-style: solid;
}
table tr:nth-child(odd) td {
border-color: #fff;
}
table tr:nth-child(odd) td {
border-color: #00f;
}
JS Fiddle demo.
Note that, if you want two cells in the first row, and three in the second, you should use the colspan attribute in your HTML (on either the first, or, as in the demo below, the second td element):
<table>
<tr>
<td></td>
<td colspan="2"></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
JS Fiddle demo.
References:
:nth-child() browser-compatibility.
CSS :nth-child() pseudo-class.
CSS
table{
background:#000;
}
tr#one{
background:blue;
}
tr#two{
background:red;
}
tr td{
background: inherit;
}
HTML
<body>
<table>
<tr id='one'>
<td>1</td>
<td>2</td>
</tr>
<tr id='two'>
<td>3</td>
<td>4</td>
</tr>
</table>
</body>
I have two tables that show data from database.
Now I set 1st table for headlines and 2nd table for the data.
I set like this
<table class="t_status">
<td>No</td>
<td>Name</td>
<td>Address</td>
</table>
In table #2
<table class="t_status">
<td>1</td>
<td>Michael</td>
<td>California</td>
<tr>
<td>2</td>
<td>Greg</td>
<td>LA</td>
Now facing the problem when data display, table 1 and table 2 set different width.
This is the CSS
table
{
empty-cells: show;
border-collapse: collapse;
width: 100%;
}
.t_status
{
border-collapse: collapse;
background: #fff;
border: 1px solid #d9d9d9;-webkit-border-radius:3px;-moz-border-radius:3px;border-radius:3px;
width: 100%;
margin-top: -1px;
}
.t_status td, th
{
border-top: 1px solid #c0c0c0;
border-bottom: 1px solid #c0c0c0;
border-left: 1px solid #c0c0c0;
border-right: 1px solid #c0c0c0;
padding: 10px;
font-size: 40pt;
font-weight: bold;
}
.t_status td
{
color: #fff;
background-color: #000;
}
.t_status th
{
font-size: 40pt;
color: #fff;
}
Try to put them like this:
<table class="t_status">
<tr>
<td>No</td>
<td>Name</td>
<td>Address</td>
</tr>
</table>
and
<table class="t_status">
<tr>
<td>1</td>
<td>Michael</td>
<td>California</td>
</tr>
<tr>
<td>2</td>
<td>Greg</td>
<td>LA</td>
</tr>
</table>
if am correct you are using two tables for scrolling effect of head and data, so you will get table header for all the data.
to achieve this effect you can try using jquery table jtable
sample code
Your html syntax is incorrect. Use tr tags:-
<table class="t_status">
<tr>
<td>No</td>
<td>Name</td>
<td>Address</td>
</tr>
</table>
You should put all information into one table, thus you can assure that the rows have the same width.
<table class="t_status">
<thead>
<tr>
<th>No</th>
<th>Name</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Michael</td>
<td>California</td>
</tr>
<tr>
<td>2</td>
<td>Greg</td>
<td>LA</td>
</tr>
</tbody>
</table>
<thead></thead> and <tbody></tbody> are not necessary.
It seems that you have forgot the <tr> tags. By the way, if you want to preserve your markup (correct or not, but two different tables), you can try with nth selectors and give a fixed width to each cell:
.t_status td:nth-child(1) {
width:2em;
}
.t_status td:nth-child(2) {
width:5em;
}
.t_status td:nth-child(3) {
width:5em;
}
Here's a working example.
Is there any way i can set padding to the thead alone of a table?
table th
{
padding:15px;
}
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Savings</th>
</tr>
<tr>
<td>Jhon</td>
<td>Smith</td>
<td>$200</td>
</tr>
</table>
<style>
table, td, th { border : 1px solid black; }
th { padding : 13px; }
td { padding : 15px; }
</style>