CSS: no top,right and bottom border on a table cells - html

I am trying to get a table with the last column cells (and header) having nor right, top and bottom border. I have searched Sobut i am unable to make what I found work,
This fiddle shows what I have tried: https://jsfiddle.net/prtome/taqge61v/
HTML
<table class="asktable">
<thead>
<th> col1</th>
<th> col1</th>
<th class="no-border-right"> col no border</th>
</thead>
<tbody><td>a</td><td>b</td><td>cell no border</td></tbody>
</table>
CSS
.asktable {
border-collapse: collapse;
border: 1px solid #ccc;
}
.asktable th {
padding: 4px 8px;
border: 1px solid #ccc;
}
.asktable td {
padding: 4px 8px;
border: 1px solid #ccc;
}
.asktable th.no-border-right{
border-top:0;
border-right:0 !important;
border-bottom:0;
}
Where is my error ? thanks for any pointer

You have a border set on the whole table so even with this removed from the th and td the border will still appear.
Also as a side note, you can do away with the extra classes to remove the border by using :last-child and omit the !important.
Ive edited your CSS below.
.asktable {
border-collapse: collapse;
}
.asktable th {
padding: 4px 8px;
border: 1px solid #ccc;
}
.asktable td {
padding: 4px 8px;
border: 1px solid #ccc;
}
.asktable th:last-child,
.asktable td:last-child {
border-top: 0;
border-right: 0;
border-bottom: 0;
}
<table class="asktable">
<thead>
<th>col1</th>
<th>col1</th>
<th class="no-border-right">col no border</th>
</thead>
<tbody>
<td>a</td>
<td>b</td>
<td>cell no border</td>
</tbody>
</table>
<p>
<br>
</p>
<table class="asktable no-border-right">
<thead>
<th>col1</th>
<th>col1</th>
<th class="no-border-right">col no border</th>
</thead>
<tbody>
<td>a</td>
<td>b</td>
<td>ccell no border</td>
</tbody>
</table>

Use hidden instead of 0, for example:
border-top:hidden !important;
border-right:hidden !important;
border-bottom:hidden !important;

remove border to table
.asktable {
/*border: 1px solid #ccc;*/
border-collapse: collapse;
}
https://jsfiddle.net/taqge61v/8/

You should use border-xxx-color:transparent; where you want no border. It will helps you.
.asktable {
border-collapse: collapse;
border: 1px solid #ccc;
}
.asktable th {
padding: 4px 8px;
border: 1px solid #ccc;
}
.asktable td {
padding: 4px 8px;
border: 1px solid #ccc;
}
/*.asktable th.no-border-right{
border-top-color:transparent !important;
border-right-color:transparent !important;
border-bottom-color:transparent !important;
}*/
.asktable .no-border-right{
border-top-color:transparent !important;
border-right-color:transparent !important;
border-bottom-color:transparent !important;
}
<table class="asktable">
<thead>
<th> col1</th>
<th> col1</th>
<th class="no-border-right"> col no border</th>
</thead>
<tbody>
<td>a</td>
<td>b</td>
<td>cell no border</td>
</tbody>
</table>
<p>
<br>
</p>
<table class="asktable no-border-right">
<thead>
<th> col1</th>
<th> col1</th>
<th class="no-border-right"> col no border</th>
</thead>
<tbody>
<td>a</td>
<td>b</td>
<td>ccell no border</td>
</tbody>
</table>

Related

How to remove space between column headers and their below row in a HTML table?

I styled a HTML table like this
I want to remove space between table column headers and their below row. I tried various tricks but nothing worked. Please note that I am also using Eric Meyer's Reset CSS v2.0.
I want to remove this red marked space without disturbing others.
My code:
#tbstud {
width:700px;
margin:50px auto;
border-collapse:separate;
border-spacing:2px;
}
.column_heading {
background-color:#d9e5f0;
-moz-border-radius:5px 5px 0 0;
-webkit-border-radius:5px 5px 0 0;
border-radius:5px 5px 0 0;
color:#000;
font-weight:bold;
height:20px;
line-height:20px;
padding:10px;
text-align:center;
}
.customer_row td {
padding:15px;
background-color:#f5f7f9;
}
.customer_row td:first-child {
border-left:3px solid #2585fe;
border-radius:5px 0 0 5px
}
.customer_row td:last-child {
border-radius:0 5px 5px 0
}
#tbstud .customer_row:nth-child(2) td:last-child {
border-radius:0 0 5px 0
}
<link rel="stylesheet" type="text/css" href="https://meyerweb.com/eric/tools/css/reset/reset.css" />
<table id="tbstud">
<tr>
<th>Sr. No.</th>
<th class="column_heading">Roll No.</th>
<th class="column_heading">Name</th>
<th class="column_heading">Class</th>
<th class="column_heading">Address</th>
</tr>
<tr class="customer_row">
<td>1</td>
<td>101</td>
<td>Sam</td>
<td>MSc</td>
<td>Delhi</td>
</tr>
<tr class="customer_row">
<td>2</td>
<td>102</td>
<td>Amit</td>
<td>BCA</td>
<td>Mumbai</td>
</tr>
<tr class="customer_row">
<td>3</td>
<td>103</td>
<td>Rahul</td>
<td>BCA</td>
<td>Delhi</td>
</tr>
<tr class="customer_row">
<td>4</td>
<td>104</td>
<td>Neha</td>
<td>BA</td>
<td>Pune</td>
</tr>
<tr class="customer_row">
<td>5</td>
<td>105</td>
<td>Pooja</td>
<td>B.Tech.</td>
<td>Chandigarh</td>
</tr>
</table>
I still need gap between each row and each cell. But just need to remove this gap between very first row and below its row.
Please remove border-spacing and use table border property. You cannot restrict border-spacing for tbody only instead what we can do is remove the border-spacing property and use border property for the table tr td
#tbstud {
width:700px;
margin:50px auto;
border-collapse:separate;
/* border-spacing:2px; */
}
/* Check Here*/
table tr td {
border: 3px solid white;
border-top: 0;
}
table tr th {
border: 2px solid white;
border-top: 0;
border-bottom: 0;
}
.column_heading {
background-color:#d9e5f0;
-moz-border-radius:5px 5px 0 0;
-webkit-border-radius:5px 5px 0 0;
border-radius:5px 5px 0 0;
color:#000;
font-weight:bold;
height:20px;
line-height:20px;
padding:10px;
text-align:center;
}
.customer_row td {
padding:15px;
background-color:#f5f7f9;
}
.customer_row td:first-child {
border-left:3px solid #2585fe;
border-radius:5px 0 0 5px
}
.customer_row td:last-child {
border-radius:0 5px 5px 0
}
#tbstud .customer_row:nth-child(2) td:last-child {
border-radius:0 0 5px 0
}
<link rel="stylesheet" type="text/css" href="https://meyerweb.com/eric/tools/css/reset/reset.css" />
<table id="tbstud">
<tr>
<th>Sr. No.</th>
<th class="column_heading">Roll No.</th>
<th class="column_heading">Name</th>
<th class="column_heading">Class</th>
<th class="column_heading">Address</th>
</tr>
<tr class="customer_row">
<td>1</td>
<td>101</td>
<td>Sam</td>
<td>MSc</td>
<td>Delhi</td>
</tr>
<tr class="customer_row">
<td>2</td>
<td>102</td>
<td>Amit</td>
<td>BCA</td>
<td>Mumbai</td>
</tr>
<tr class="customer_row">
<td>3</td>
<td>103</td>
<td>Rahul</td>
<td>BCA</td>
<td>Delhi</td>
</tr>
<tr class="customer_row">
<td>4</td>
<td>104</td>
<td>Neha</td>
<td>BA</td>
<td>Pune</td>
</tr>
<tr class="customer_row">
<td>5</td>
<td>105</td>
<td>Pooja</td>
<td>B.Tech.</td>
<td>Chandigarh</td>
</tr>
</table>
Maybe you can use this kind of hack:
<link rel="stylesheet" type="text/css" href="https://meyerweb.com/eric/tools/css/reset/reset.css" />
<table id="tbstud">
<thead>
<tr>
<th>Sr. No.</th>
<th>
<div class="column_heading">Roll No.</div>
</th>
<th>
<div class="column_heading">Name</div>
</th>
<th>
<div class="column_heading">Class</div>
</th>
<th>
<div class="column_heading">Address</div>
</th>
</tr>
</thead>
<tbody>
<tr class="customer_row">
<td>1</td>
<td>101</td>
<td>Sam</td>
<td>MSc</td>
<td>Delhi</td>
</tr>
<tr class="customer_row">
<td>2</td>
<td>102</td>
<td>Amit</td>
<td>BCA</td>
<td>Mumbai</td>
</tr>
<tr class="customer_row">
<td>3</td>
<td>103</td>
<td>Rahul</td>
<td>BCA</td>
<td>Delhi</td>
</tr>
<tr class="customer_row">
<td>4</td>
<td>104</td>
<td>Neha</td>
<td>BA</td>
<td>Pune</td>
</tr>
<tr class="customer_row">
<td>5</td>
<td>105</td>
<td>Pooja</td>
<td>B.Tech.</td>
<td>Chandigarh</td>
</tr>
</tbody>
</table>
#tbstud {
width: 700px;
margin: 50px auto;
border-collapse: separate;
border-spacing: 2px;
}
.column_heading {
background-color: #d9e5f0;
-moz-border-radius: 5px 5px 0 0;
-webkit-border-radius: 5px 5px 0 0;
border-radius: 5px 5px 0 0;
color: #000;
font-weight: bold;
height: 20px;
line-height: 20px;
padding: 10px;
text-align: center;
margin-bottom: -2px;
}
.customer_row td {
padding: 15px;
background-color: #f5f7f9;
}
.customer_row td:first-child {
border-left: 3px solid #2585fe;
border-radius: 5px 0 0 5px;
}
.customer_row td:last-child {
border-radius: 0 5px 5px 0;
}
#tbstud .customer_row:nth-child(2) td:last-child {
border-radius: 0 0 5px 0;
}
Working codepen: https://codepen.io/leo-melin/pen/rNaWxOq
So you just put the contents of tags inside divs that have margin-bottom: -2px css in addition to normal heading style.
Also added <thead> and <tbody> tags
removed border-spacing
no gap only after header
black color as example to be visible
#tbstud tr th{
border: 1px solid black;
border-bottom: 0px;
}
.customer_row td{
border: 1px solid black;
}
#tbstud tr:last-child td{
border-bottom: 2px solid black;
}
.customer_row:nth-child(2) td{
border-top: 0px;
}
If I understood what you mean then the solution would be to give the .column_heading a position: relative;, then add a .column_heading:after to add a line and the bottom of the <th> tag.
Try this
.column_heading:after {
content: '';
position: absolute;
left: 0;
bottom: -3px;
width: 100%;
height: 3px;
background-color: #d9e5f0;
}
Don't forget to give the .column_heading a position: relative;
Hope this help =]
Remove border-spacing property on #tbstud
and add this css
.column_heading{
border-left: 1px solid #fff;
}
.customer_row td {
border-left: 1px solid #fff;
border-bottom: 1px solid #fff;
}

How to make a custom looking table with HTML and CSS?

I was wondering how could I create a custom looking Table like that?
body {
background-color: white;
}
table {
border: 1px solid black;
border-radius: 15px;
background: lightgrey;
color: black;
padding-left: 15px;
padding-right: 15px;
}
.t_head {
background-color: dodgerblue;
}
td {
padding-left: 10px;
padding-right: 10px;
}
#t_body {
background-color: grey;
}
<div id="test_div">
<table>
<thead>
<tr>
<div class="t_head">
<th>Test Header</th>
<th>Test Header</th>
<th>Test Header</th>
</div>
</tr>
</thead>
<tbody>
<div id="t_body">
<tr>
<th>Test data</th>
<th>Test data</th>
<th>Test data</th>
</tr>
<tr>
<th>Test data</th>
<th>Test data</th>
<th>Test data</th>
</tr>
</div>
</tbody>
</table>
</div>
I tried to add some styling for thead/tr element but the results are pretty much the same. Also, the borders in thead is something I can't add. I am very new to html and css and my searching attempts weren't very successful. I would appreciate any help!
Firstly, fix your html - remove the divs from the table as they are invalid, then you can put the blue colour on the cells in the header and the grey on the cells in the body.
I have put a whole border on the table and hidden the overflow for the rounded edges, then on the header I have just added a bottom and left border to fill in the lines - removing the left from the first cell (as that is on the outline of the whole table).
The border-spacing just removes any space between the cells so the borders are next to each other (like using border-collapse)
body {
background-color: white;
}
table {
overflow: hidden;
color: black;
border: 1px solid #000000;
border-radius: 15px;
border-spacing: 0;
}
thead th {
border-bottom: 1px solid black;
border-left: 1px solid black;
padding: 5px 10px;
background-color: dodgerblue;
border-collapse: collapse;
}
thead th:first-child {
border-left: none;
}
td {
padding: 5px 10px;
background: lightgrey;
}
<div id="test_div">
<table>
<thead>
<tr>
<th>Test Header</th>
<th>Test Header</th>
<th>Test Header</th>
</tr>
</thead>
<tbody>
<tr>
<td>Test data</td>
<td>Test data</td>
<td>Test data</td>
</tr>
<tr>
<td>Test data</td>
<td>Test data</td>
<td>Test data</td>
</tr>
</tbody>
</table>
</div>
You could do this with divs and flex, it's easier
https://codepen.io/anon/pen/YJyBmy
.d-flex {
display: flex;
}
#table {
border: 4px solid black;
border-radius: 20px;
width: 500px;
}
#thead>div,
#tbody>div {
border-left: 4px solid black;
padding: 15px;
width: 33%;
}
#thead>div:first-child,
#tbody>div:first-child {
border: 0;
}
#thead {
background: dodgerblue;
border-radius: 15px 15px 0 0;
border-bottom: 4px solid black;
}
#tbody {
background: grey;
border-radius: 0 0 15px 15px;
}
<div id="table">
<div id="thead" class="d-flex">
<div>test</div>
<div>test</div>
<div>test</div>
</div>
<div id="tbody" class="d-flex">
<div>test</div>
</div>
</div>

how to make a space-keeping column use css and table tag

What is the most elegant way to remove the up down border?
table {
border: 1px solid #CCC;
border-collapse: collapse;
text-align: center;
}
.noborder {
border: none;
width: 50px;
}
<br>
<table border='1' width='500'>
<tr>
<th>Product</th>
<th>Description</th>
<th>Price</th>
<th>Quantity</th>
<th class="noborder"> </th>
<th>Delete</th>
</tr>
<tr>
<td>AA</td>
<td>BB</td>
<td>CC</td>
<td>DD</td>
<td class="noborder"> </td>
<td>FF</td>
</tr>
</table>
JSfiddle Demo
You need to apply border for the th and td elements and not for the entire table. Setting border for the table will not be affected by the noborder class applied on the child elements.
Updated JSfiddle
table {
border-collapse: collapse;
text-align: center;
}
.noborder {
border: none;
width: 50px;
}
th,
td {
border: 1px solid #CCC;
}
<br>
<table width='500'>
<tr>
<th>Product</th>
<th>Description</th>
<th>Price</th>
<th>Quantity</th>
<th class="noborder"> </th>
<th>Delete</th>
</tr>
<tr>
<td>AA</td>
<td>BB</td>
<td>CC</td>
<td>DD</td>
<td class="noborder"> </td>
<td>FF</td>
</tr>
</table>
I'd say specify only the borders you need.
If you don't want the top and bottom... only set the left and right border.
table {
border-left: 1px solid #000;
border-left: 1px solid #000;
}
If you're trying to remove only the top and bottom of that blank column, you could try setting the border for each column separately, thus allowing the removal of the desired border.
td {
border: 1px solid #000;
}
#blank-td {
border: none /* or even 1px solid #fff */;
}
Just mess around with it
More info: http://www.w3schools.com/css/css_border.asp

Table Row Border - Half In, Half Out

I'm trying to style table with what I thought would be a fairly simple style to achieve but have run in to a little issue.
The table will show a coloured indicator on the left hand side of each row so I'm using border-left: 5px solid red; to add it. However, although the border applies - half of it is inside the row and half outside. I've tried adding border-collapse: collapse to no avail, I'm also using box-sizing: border-box but still have the same issue.
Finally, I've also tried adding the border to the first-child cell (td) but the same issue appears.
I've set up an example of what's happening - I've put in an oversized border to highlight the issue:
http://www.cssdesk.com/TVa67
Has anyone run into this before or have any solutions?
body {
background: blue;
}
table {
border-collapse: collapse;
box-sizing: border-box;
table-layout: fixed;
width: 100%;
}
th,
td {
background-color: #fff;
padding: 10px 15px 8px;
}
th {
border-bottom: 1px solid blue;
font-weight: normal;
text-align: left;
}
td {
border-bottom: 1px solid gray;
}
tr.low {
border-left: 25px solid red;
}
<table style="
border-collapse: collapse;
">
<tbody>
<tr>
<th>#</th>
<th>Status</th>
<th>Title</th>
<th>Project</th>
<th>Assigned To</th>
<th>Age</th>
</tr>
<tr class="low">
<td>1</td>
<td>New</td>
<td>This is an example ticket</td>
<td>Something</td>
<td>Something</td>
<td>2 days ago</td>
</tr>
</tbody>
</table>
However, although the border applies - half of it is inside the row
and half outside
This behaviour is expected and is as per specs. Refer to: http://www.w3.org/TR/CSS2/tables.html#collapsing-borders where it says:
Borders are centered on the grid lines between the cells...
It also illustrates that with a diagram with description.
Has anyone run into this before or have any solutions?
Yes, it can be easily demonstrated as in this fiddle: http://jsfiddle.net/abhitalks/xs7L9wn1/1/ and the below Snippet:
* { box-sizing: border-box; }
table {
border-collapse: collapse;
border: 1px solid gray;
table-layout: fixed; width: 70%;
margin: 0 auto;
}
th, td {
border: 1px solid gray;
padding: 6px;
text-align: center;
}
tbody > tr:nth-child(1) > td:first-child { border-left: 16px solid red; }
tbody > tr:nth-child(2) > td:first-child { border-left: 8px solid green; }
tbody > tr:nth-child(3) > td:first-child { border-left: 24px solid blue; }
tbody > tr:nth-child(1) > td:last-child { border-left: 16px solid red; }
tbody > tr:nth-child(2) > td:last-child { border-left: 8px solid green; }
tbody > tr:nth-child(3) > td:last-child { border-left: 24px solid blue; }
<table>
<thead>
<tr>
<th>#</th>
<th>Header 1</th>
<th>Header 2</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Caption</td>
<td>Description</td>
</tr>
<tr>
<td>2</td>
<td>Caption</td>
<td>Description</td>
</tr>
<tr>
<td>3</td>
<td>Caption</td>
<td>Description</td>
</tr>
</tbody>
</table>
Solution:
Just add a transparent border of the same width to all rows. That way the border-width will be same and it will neatly align. (Update: added a white border-left to first column to hide the hanging border on highlighted cell. As pointed out by your comment.)
th, td { border-left: 15px solid transparent; }
tr > td:first-child, tr > th:first-child { border-left: 5px solid #fff; }
tr.low > td:first-child { border-left: 5px solid red; }
Example Fiddle: https://jsfiddle.net/abhitalks/s9taanz7/5/
Snippet:
* { box-sizing: border-box; }
body { background-color: blue; }
table {
border-collapse: collapse;
table-layout: fixed; width: 100%;
}
th, td {
background-color: #fff;
padding: 10px 15px 8px 8px;
border-left: 5px solid transparent;
border-bottom: 1px solid gray;
}
th {
border-bottom: 1px solid blue;
font-weight: normal; text-align: left;
}
tr > td:first-child, tr > th:first-child { border-left: 10px solid #fff; }
tr.low > td:first-child { border-left: 10px solid red; }
<table>
<thead>
<tr>
<th>#</th>
<th>Status</th>
<th>Title</th>
<th>Project</th>
<th>Assigned To</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr class="">
<td>1</td>
<td>New</td>
<td>This is an example ticket</td>
<td>Something</td>
<td>Something</td>
<td>2 days ago</td>
</tr>
<tr class="low">
<td>2</td>
<td>New</td>
<td>This is an example ticket</td>
<td>Something</td>
<td>Something</td>
<td>2 days ago</td>
</tr>
<tr class="">
<td>3</td>
<td>New</td>
<td>This is an example ticket</td>
<td>Something</td>
<td>Something</td>
<td>2 days ago</td>
</tr>
</tbody>
</table>
However, this approach will have a side-effect of hidden border-bottom because the border-left overlaps it.
Solution 2:
You could have an extra cell on the left to use as indicator. You can then control this by use of colgroup. This approach is neater than above and also requires you to have the width specified only once in css.
Example Fiddle 2: http://jsfiddle.net/abhitalks/z7u1nhwt/1/
Snippet 2:
* { box-sizing: border-box; }
body { background-color: blue; }
table {
border-collapse: collapse;
table-layout: fixed; width: 100%;
}
th, td {
background-color: #fff;
padding: 10px 15px 8px 8px;
border-bottom: 1px solid gray;
}
th {
border-bottom: 1px solid blue;
font-weight: normal; text-align: left;
}
.col1 { width: 10px; }
tr.low > td:first-child {
background-color: #f00;
}
<table>
<colgroup>
<col class="col1" />
<col class="coln" span="6" />
</colgroup>
<thead>
<tr>
<th></th>
<th>#</th>
<th>Status</th>
<th>Title</th>
<th>Project</th>
<th>Assigned To</th>
<th>Age</th>
</tr>
</thead>
<tbody>
<tr class="">
<td></td>
<td>1</td>
<td>New</td>
<td>This is an example ticket</td>
<td>Something</td>
<td>Something</td>
<td>2 days ago</td>
</tr>
<tr class="low">
<td></td>
<td>2</td>
<td>New</td>
<td>This is an example ticket</td>
<td>Something</td>
<td>Something</td>
<td>2 days ago</td>
</tr>
<tr class="">
<td></td>
<td>3</td>
<td>New</td>
<td>This is an example ticket</td>
<td>Something</td>
<td>Something</td>
<td>2 days ago</td>
</tr>
</tbody>
</table>
And of course, you can also try the approach of using pseudo-element as proposed by #misterManSam, depending on ease of implementation for you.

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;.