Is it possible to border a table row, <tr> in one go instead of giving a border to individual cells, <td> like,
<table cellpadding="0" cellspacing="0" width="100%" style="border: 1px;" rules="none">
<tbody>
<tr>
<th style="width: 96px;">Column 1</th>
<th style="width: 96px;">Column 2</th>
<th style="width: 96px;">Column 3</th>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td style="border-left: thin solid; border-top: thin solid; border-bottom: thin solid;"> </td>
<td style="border-top: thin solid; border-bottom: thin solid;"> </td>
<td style="border-top: thin solid; border-bottom: thin solid; border-right: thin solid;"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
This gives a border around the given <tr> but it requires a border around individual cells.
Can we give a border to <tr> only in one go?
→ jsFiddle
You can set border properties on a tr element, but according to the CSS 2.1 specification, such properties have no effect in the separated borders model, which tends to be the default in browsers. Ref.: 17.6.1 The separated borders model. (The initial value of border-collapse is separate according to CSS 2.1, and some browsers also set it as default value for table. The net effect anyway is that you get separated border on almost all browsers unless you explicitly specifi collapse.)
Thus, you need to use collapsing borders. Example:
<style>
table { border-collapse: collapse; }
tr:nth-child(3) { border: solid thin; }
</style>
Absolutely! Just use
<tr style="outline: thin solid">
on which ever row you like. Here's a fiddle.
Of course, as people have mentioned, you can do this via an id, or class, or some other means if you wish.
Yes. I updated my answer DEMO
table td {
border-top: thin solid;
border-bottom: thin solid;
}
table td:first-child {
border-left: thin solid;
}
table td:last-child {
border-right: thin solid;
}
If you want to style only one <tr> you can do it with a class: Second DEMO
You can use the box-shadow property on a tr element as a subtitute for a border. As a plus, any border-radius property on the same element will also apply to the box shadow.
box-shadow: 0px 0px 0px 1px rgb(0, 0, 0);
Make use of CSS classes:
tr.border{
outline: thin solid;
}
and use it like:
<tr class="border">...</tr>
Left cell:
style="border-style:solid;border-width: 1px 0px 1px 1px;"
midd cell(s):
style="border-style:solid;border-width: 1px 0px 1px 0px;"
right cell:
style="border-style:solid;border-width: 1px 1px 1px 0px;"
<table cellpadding="0" cellspacing="0" width="100%" style="border: 1px;" rules="none">
<tbody>
<tr>
<th style="width: 96px;">Column 1</th>
<th style="width: 96px;">Column 2</th>
<th style="width: 96px;">Column 3</th>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td style="border-left: thin solid; border-top: thin solid; border-bottom: thin solid;"> </td>
<td style="border-top: thin solid; border-bottom: thin solid;"> </td>
<td style="border-top: thin solid; border-bottom: thin solid; border-right: thin solid;"> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td> </td>
</tr>
</tbody>
</table>
You can try this (Border Just bottom of every row)
table {
border-collapse: collapse;
}
tr {
border-bottom: 1px solid black;
}
adding border-spacing: 0rem 0.5rem; creates a space for each cell (td, th) items on its bottom while leaving no space between the cells
table.app-table{
border-collapse: separate;
border-spacing: 0rem 0.5rem;
}
table.app-table thead tr.border-row the,
table.app-table tbody tr.border-row td,
table.app-table tbody tr.border-row th{
border-top: 1px solid #EAEAEA;
border-bottom: 1px solid #EAEAEA;
vertical-align: middle;
white-space: nowrap;
font-size: 0.875rem;
}
table.app-table thead tr.border-row th:first-child,
table.app-table tbody tr.border-row td:first-child{
border-left: 1px solid #EAEAEA;
}
table.app-table thead tr.border-row th:last-child,
table.app-table tbody tr.border-row td:last-child{
border-right: 1px solid #EAEAEA;
}
After fighting with this for a long time I have concluded that the spectacularly simple answer is to just fill the table with empty cells to pad out every row of the table to the same number of cells (taking colspan into account, obviously). With computer-generated HTML this is very simple to arrange, and avoids fighting with complex workarounds. Illustration follows:
<h3>Table borders belong to cells, and aren't present if there is no cell</h3>
<table style="border:1px solid red; width:100%; border-collapse:collapse;">
<tr style="border-top:1px solid darkblue;">
<th>Col 1<th>Col 2<th>Col 3
<tr style="border-top:1px solid darkblue;">
<td>Col 1 only
<tr style="border-top:1px solid darkblue;">
<td colspan=2>Col 1 2 only
<tr style="border-top:1px solid darkblue;">
<td>1<td>2<td>3
</table>
<h3>Simple solution, artificially insert empty cells</h3>
<table style="border:1px solid red; width:100%; border-collapse:collapse;">
<tr style="border-top:1px solid darkblue;">
<th>Col 1<th>Col 2<th>Col 3
<tr style="border-top:1px solid darkblue;">
<td>Col 1 only<td><td>
<tr style="border-top:1px solid darkblue;">
<td colspan=2>Col 1 2 only<td>
<tr style="border-top:1px solid darkblue;">
<td>1<td>2<td>3
</table>
Related
Im trying to select a section on a table by making its border thicker on a selected area, so I need to change the border on specifics cells to get something like this.
this is my best try for the upper one.
every selected cell has a "selected" class, and if there is a selected cell, the row has a selected class too. I hope you get it ;)
.table tr.selected:first-child td.selected{
border-top-width:5px;
border-top-color:#000;
}
is it possible?
If you are not restricted with these specific class names, you can add a custom class to cells of the last selected row. If you cannot modify the HTML, you can try to add the custom classes with JavaScript.
var selectedRows = document.querySelectorAll('tr.selected');
selectedRows[selectedRows.length-1].classList.add('last-selected-row');
table{
border-collapse: collapse;
}
table tr td{
border: 1px solid #e2e4e8;
padding: 10px;
}
table td.selected{
background-color: #cae5cd;
}
table tr.selected td.selected:first-child{
border-left: 3px solid black;
border-right: none;
}
table tr.selected td.selected:last-child{
border-right: 3px solid black;
border-left: none;
}
table tr.selected td.selected + td:not(.selected){
border-left: 3px solid black;
}
table tr:not(.selected) + tr.selected td.selected{
border-top: 3px solid black;
border-bottom: 1px solid #e2e4e8;
}
table tr.last-selected-row td.selected{
border-bottom: 3px solid black;
}
<table>
<tr>
<td>far east</td>
<td></td>
<td>USD</td>
</tr>
<tr>
<td>pol</td>
<td>pod</td>
<td>USD</td>
</tr>
<tr class="selected">
<td class="selected">VALENCIA MADRID</td>
<td class="selected">BRISBANE</td>
<td>USD</td>
</tr>
<tr class="selected">
<td class="selected">VALENCIA MADRID</td>
<td class="selected">Melbourne</td>
<td>USD</td>
</tr>
<tr class="selected">
<td class="selected">VALENCIA MADRID</td>
<td class="selected">SYDNEY</td>
<td>USD</td>
</tr>
<tr>
<td>VALENCIA MADRID</td>
<td>Chongoing</td>
<td>USD</td>
</tr>
</table>
The padding and the border styles I have added in the snippet are just for demo purpose.
Html is not my specialty :)
I have an Html table and I want to have a solid line between each row. I've done it by defining a border-bottom on each <td> tag, like so:
<td style="border-bottom: 1px solid #0066ff;">[content]</td>
But it comes out with a one-pixel gap in the line, as seen below:
I tried putting the border-bottom in the <tr> tag, but that didn't work at all. What's the correct way to do this?
You may use the CSS attribute border-collapse and set it to collapse:
table
{
border-collapse: collapse;
}
td
{
border-bottom: solid 1px black;
}
<table>
<tr>
<td>Test</td>
<td>Test 2</td>
</tr>
<tr>
<td>Test</td>
<td>Test 2</td>
</tr>
</table>
Try this.
table {
border-collapse: collapse;
}
td {
padding: 10px 0;
}
tr {
border-bottom: 1px solid #0066ff;
}
Give cellspacing 0 to the table
<table cellspacing="0">
<tr>
<td style="border-bottom: solid 1px;">sdfa</td>
<td style="border-bottom: solid 1px;">asfsaf</td>
</tr>
</table>
Example: JSFiddle
I noticed that when I apply a border-style to my table tag, it only works for solid, dashed or dotted, but it doesn't for double, groove and so on.
Is there a limitation for border-style for tables? Or am I doing something wrong?
<table border="1px" style="border-collapse:collapse; 1px black; border-style:double;">
<thead>
<tr>
<th colspan="2" style="padding:5px; background-color:blue; color:white; font-family:Arial; font-size:14px">Pricelist</th>
</tr>
<tr>
<th style="padding:5px">Product</th>
<th style="padding:5px">Price</th>
</tr>
</thead>
<tbody>
<tr>
<td style="padding:5px">item1</td>
<td style="padding:5px">price1</td>
</tr>
<tr>
<td style="padding:5px">item2</td>
<td style="padding:5px">price2</td>
</tr>
<tr>
<td style="padding:5px">item3</td>
<td style="padding:5px">price3</td>
</tr>
</tbody>
</table>
You should put 1px black into the property like, border-width: 1px; border-color: black; border-style: double; or just use border: 1px black double; to make it work. The border="1px" works "inside" the table, which you can set styles of tr, td, and th in css. I set different widths, 1px inside and 10px outside for you to see the differences clearly.
<table border="1px" style="border: 10px black double;">
<thead>
<tr>
<th colspan="2" style="padding:5px; background-color:blue; color:white; font-family:Arial; font-size:14px">Pricelist</th>
</tr>
<tr>
<th style="padding:5px">Product</th>
<th style="padding:5px">Price</th>
</tr>
</thead>
<tbody>
<tr>
<td style="padding:5px">item1</td>
<td style="padding:5px">price1</td>
</tr>
<tr>
<td style="padding:5px">item2</td>
<td style="padding:5px">price2</td>
</tr>
<tr>
<td style="padding:5px">item3</td>
<td style="padding:5px">price3</td>
</tr>
</tbody>
</table>
Your table border needs a "width." Try..
table {
border-collapse: collapse;
border-style: double;
border-width: 4px;
Border Width is Too Small.
Specifying too small of a border-width will not allow for the border-style to be double. Essentially, it's too small to show two separate lines.
For example, if use something like border-top: #333 double 1px; then only a single line will be shown.
In fact, using 2px for the width, like border-top: #333 double 2px;, will still not show a double line. Instead, it will just show a thicker, 2px-wide line.
I had to use at least 3px for the double border to show properly, like border-top: #333 double 3px;.
This makes sense, considering it takes 3 pixels to show two 1px lines with a 1px gap between them.
1px (line) + 1px (gap) + 1px (line) = 3px
So your two options are:
Specify a bigger border-width, like border-top: #333 double 3px;.
-or-
Do not specify the border-width, like border-top: #333 double;, and let the browser/renderer figure it out.
Hopefully that helps others.
Pictures are worth much more than words, in this case. See how the intersection of the top, black bar and the lightgrey, vertical bar between 'Left' and 'Right' is lightgrey instead of black? Is there a way to ensure that one border is shown 'above' another, kind of like a z-index?
How it looks:
How I want it to look (adjusted with image editor):
Here's a jsfiddle for my issue. If you don't like jsfiddle, for whatever reason, my HTML and CSS are below.
HTML:
<table id="tiresTable" class="table">
<tr class="firstRow">
<td class="thSim">Tires:</td>
<td class="thXAxis borderRight">Left</td>
<td class="thXAxis">Right</td>
</tr>
<tr class="borderBottom">
<td class="thYAxis">Front</td>
<td class="borderRight"></td>
<td></td>
</tr>
<tr class="borderBottom">
<td class="thYAxis">Rear</td>
<td class="borderRight"></td>
<td></td>
</tr>
<tr>
<td class="thYAxis">Spare</td>
<td colspan="2"></td>
</tr>
</table>
CSS:
#tiresTable{
border-collapse: collapse;
}
#tiresTable tr.firstRow td{
border-bottom: 1px solid black;
}
#tiresTable td.thSim, #tiresTable td.thYAxis{
border-right: 1px solid black;
}
#tiresTable td.borderRight{
border-right: 1px solid lightgrey;
}
#tiresTable tr.borderBottom{
border-bottom: 1px solid lightgrey;
}
Please note that, due to technological constraints, I cannot use CSS3 properties. Also note that I will not be offended if you edit my question title if you can describe the issue more eloquently than I have.
EDIT:
It was a little hacky but I was able to do something that works as you need.
HTML:
<table id="tiresTable" class="table">
<tr class="firstRow">
<td class="thSim">Tires:</td>
<td class="thXAxis borderRight">Left</td>
<td class="thXAxis">Right</td>
</tr>
<tr class="border-bottom">
<td colspan="3"><div class="black"></div></td>
</tr>
<tr class="borderBottom">
<td class="thYAxis">Front</td>
<td class="borderRight"></td>
<td></td>
</tr>
<tr class="borderBottom">
<td class="thYAxis">Rear</td>
<td class="borderRight"></td>
<td></td>
</tr>
<tr>
<td class="thYAxis">Spare</td>
<td colspan="2"></td>
</tr>
</table>
CSS:
#tiresTable{
border-collapse: collapse;
}
#tiresTable tr.borderBottom{
border-bottom: 1px solid lightgrey;
}
#tiresTable td.borderRight{
border-right: 1px solid lightgrey;
}
#tiresTable td.thSim, #tiresTable td.thYAxis{
border-right: 1px solid black;
}
.border-bottom {
height: 1px;
}
.border-bottom td {
height: 1px;
border: 0px;
padding: 0px;
}
.black {
background-color: black;
height: 1px;
}
I removed anything that is not really required, and used altered classes names to know easily what is new and what is not.
Fiddle: http://jsfiddle.net/ru92py4m/15/
I have an HTML table with the class "productsTable". I want to give each cell in the table a border. Now I have tried the following in my stylesheet but none of the two works. What am I doing wrong? Thank You
td.productsTable
{
border: 1px dotted #999999;
}
.productsTable td
{
border: 1px dotted #999999;
}
HTML:
<table class="productsTable" width="100%" height="100%" cellspacing="2px;">
<tr>
<td width="40%">We Offer:</td>
<td class="ephoneFree tableHeader" width="20%" align="center">e-phone FREE</td>
<td class="personal tableHeader" width="20%" align="center">Personal</td>
<td class="PBX tableHeader" width="20%" align="center">Pro PBX</td>
</tr>
<tr>
<td width="40%">Pricing</td>
<td width="20%" align="center">FREE</td>
<td width="20%" align="center">£3 per month</td>
<td width="20%" align="center">From £5 per month</td>
</tr>
</table>
td.productsTable won't work because you have no <td> elements with a productsTable class.
However, your second CSS rule, .productsTable td, this will work because you do have <td> elements that have a parent element with the class productsTable.
I've made a quick fiddle of this, and you can see it working correctly:
td {
border: 1px dotted #999;
}
<table width="100%" height="100%" cellspacing="2px;">
<tr>
<td width="40%">We Offer:</td>
<td width="20%" align="center">e-phone FREE</td>
<td width="20%" align="center">Personal</td>
<td width="20%" align="center">Pro PBX</td>
</tr>
<tr>
<td width="40%">Pricing</td>
<td width="20%" align="center">FREE</td>
<td width="20%" align="center">£3 per month</td>
<td width="20%" align="center">From £5 per month</td>
</tr>
</table>
If this isn't working for you, its likely that you have either not correctly linked your CSS file, or there is another CSS rule overriding this. Try inspecting element to see.
I want to give each cell in the table a border.
What I've understand is you want cell border like this:
Here is the fiddle of what you want.
Use following CSS:
table.productsTable {
border-width: 1px;
border-spacing: 2px;
border-style: outset;
border-color: gray;
border-collapse: separate;
background-color: white;
}
table.productsTable td {
border-width: 1px;
padding: 1px;
border-style: inset;
border-color: gray;
background-color: white;
-moz-border-radius: ;
}
Hope this helps.
write like this:
.products td
{
border: 1px dotted #999999;
}
HTML
<table class="products">
<tr>
<td></td>
</tr>
</table>
Below code does the following:-
1. gives single border to td's
2. separate border to the table.
Environment:-
Works on FF 34.0.
Untried for html6:-
To run it using html6, try it with html:x eg. html:head, html:title, etc.
<!DOCTYPE html>
<html>
<head>
<script>
</script>
<title>Welcome to the jungle</title>
<style>
.table_main {
border-top-style: ridge;
border-bottom-style: ridge;
border-left-style: ridge;
border-right-style: ridge;
border-color: red;
border-width: 3px;
}
.table_main td {
background: #A38055;
border-right: solid 1px white ;
border-bottom: 1px solid white;
text-align: center;
}
.table_main th {
background: #DCDCDC;
border-right: solid 1px white ;
border-bottom: 1px solid white;
text-align: center;
}
</style>
</head>
<body>
<h1>Welcome to the jungle</h1>
<table class="table_main" width="400" align="center" border="0" cellspacing="0" cellpadding="0">
<thead> <th>THead1</th> <th>THead2</th> <th>THead3</th>
</thead>
<tbody>
<tr> <td>A</td> <td>B</td> <td>C</td> </tr>
<tr> <td>X</td> <td>Y</td> <td>Z</td> </tr>
<tr> <td>Xena</td> <td>Yoda</td> <td>Zohan</td> </tr>
</tbody>
</table>
</body>
</html>