I have simple table on which I'm trying to add colgroup and col but they aren't visible. It is also partly break the responsiveness of the table.
On mobile version the red cols are visible but are wrong.
Here is the table
table {
border: 1px solid #ccc;
border-collapse: collapse;
margin: 0;
padding: 0;
width: 100%;
table-layout: fixed;
}
table caption {
font-size: 1.5em;
margin: .5em 0 .75em;
}
table tr {
background-color: #f8f8f8;
border: 1px solid #ddd;
padding: .35em;
}
table th,
table td {
padding: .625em;
text-align: center;
}
table th {
font-size: .85em;
letter-spacing: .1em;
text-transform: uppercase;
}
#media screen and (max-width: 600px) {
table {
border: 0;
}
table caption {
font-size: 1.3em;
}
table thead {
border: none;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
table tr {
border-bottom: 3px solid #ddd;
display: block;
margin-bottom: .625em;
}
table td {
border-bottom: 1px solid #ddd;
display: block;
font-size: .8em;
text-align: right;
}
table td::before {
content: attr(data-label);
float: left;
font-weight: bold;
text-transform: uppercase;
}
table td:last-child {
border-bottom: 0;
}
}
<table>
<caption>Statement Summary</caption>
<colgroup>
<col span="2" style="background-color:red; text-align: center;">
<col style="background-color:yellow">
</colgroup>
<thead>
<tr>
<th scope="col">Account</th>
<th scope="col">Due Date</th>
<th scope="col">Amount</th>
<th scope="col">Period</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Due Date">04/01/2016</td>
<td data-label="Amount">$1,190</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
</tr>
<tr>
<td scope="row" data-label="Account">Visa - 6076</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Amount">$2,443</td>
<td data-label="Period">02/01/2016 - 02/29/2016</td>
</tr>
<tr>
<td scope="row" data-label="Account">Corporate AMEX</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Amount">$1,181</td>
<td data-label="Period">02/01/2016 - 02/29/2016</td>
</tr>
<tr>
<td scope="row" data-label="Account">Visa - 3412</td>
<td data-label="Due Date">02/01/2016</td>
<td data-label="Amount">$842</td>
<td data-label="Period">01/01/2016 - 01/31/2016</td>
</tr>
</tbody>
</table>
And here is the Jsfiddle where you can see the responsiveness: https://jsfiddle.net/d5yfteck/
How can I use colgroup and col?
This line:
table tr {
background-color: #f8f8f8;
}
is overriding the colgroup definitions.
Without that line your code is working fine:
your code with colgroup
UPDATE:
If you wish to achieve the same effect on mobile,
in your mobile layout the columns presented as rows so one solution is to use classes in the media tag (.red .yellow), also see that tbody should be set with other color.
Related
I'm trying to recreate the attached table to be responsive in a similar style as the below code.
I am unsure if I explaining myself well enough but I am having trouble figuring out how I can reference the min/max data which also shows up along with DK (mobile view)
<style>
table {
border: 1px solid #ccc;
border-collapse: collapse;
margin: 0;
padding: 0;
width: 100%;
table-layout: fixed;
}
table caption {
font-size: 1.5em;
margin: .5em 0 .75em;
}
table tr {
background-color: #f8f8f8;
border: 1px solid #ddd;
padding: .35em;
}
table th,
table td {
padding: .625em;
text-align: center;
}
table th {
font-size: .85em;
letter-spacing: .1em;
text-transform: uppercase;
}
#media screen and (max-width: 600px) {
table {
border: 0;
}
table caption {
font-size: 1.3em;
}
table thead {
border: none;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
table tr {
border-bottom: 3px solid #ddd;
display: block;
margin-bottom: .625em;
}
table td {
border-bottom: 1px solid #ddd;
display: block;
font-size: .8em;
text-align: right;
}
table td::before {
/*
* aria-label has no advantage, it won't be read inside a table
content: attr(aria-label);
*/
content: attr(data-label);
float: left;
font-weight: bold;
text-transform: uppercase;
}
table td:last-child {
border-bottom: 0;
}
}
</style>
HTML
<table>
<thead>
<tr>
<th scope="col">Product</th>
<th scope="col">Material characteristics yield strength <sub>M (N/mm²)</sub></th>
<th scope="col">Characteristic pull-out resistance <sub>f (N/mm²)</sub></th>
<th scope="col">Assigned density <sub>p (kg/m³)</sub></th>
<th scope="col">Characteristic head pull-through resistance <sub>f (N/mm²)</sub></th>
<th scope="col">Characteristic tensile resistance <sub>f {kN}</sub></th>
<th scope="col">Characteristic torsional resistance <sub>f (N*m)</sub></th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Product">WKCP Ø6</td>
<td data-label="Material characteristics yield strength">10.0 <sub>M (N/mm²)</sub></td>
<td data-label="Characteristic pull-out resistance">12.0 <sub>f (N/mm²)</sub></td>
<td data-label="Assigned density">350 <sub>p (kg/m³)</sub></td>
<td data-label="Characteristic head pull-through resistance">9.4 <sub>f (N/mm²)</sub></td>
<td data-label="Characteristic tensile resistance">13.0 <sub>f {kN}</sub></td>
<td data-label="Characteristic torsional resistance">10.0 <sub>f (N*m)</sub></td>
</tr>
<td scope="row" data-label="Account">WKCP Ø8</td>
<td data-label="Material characteristics yield strength">25.0 <sub>M (N/mm²)</sub></td>
<td data-label="Characteristic pull-out resistance">12.0 <sub>f (N/mm²)</sub></td>
<td data-label="Assigned density">350 <sub>p (kg/m³)</sub></td>
<td data-label="Characteristic head pull-through resistance">9.4 <sub>f (N/mm²)</sub></td>
<td data-label="Characteristic tensile resistance">25.0 <sub>f {kN}</sub></td>
<td data-label="Characteristic torsional resistance">27.0 <sub>f (N*m)</sub></td>
</tr>
<tr>
<td scope="row" data-label="Acount">WKCP Ø10</td>
<td data-label="Material characteristics yield strength">43.0 <sub>M (N/mm²)</sub></td>
<td data-label="Characteristic pull-out resistance">11.0 <sub>f (N/mm²)</sub></td>
<td data-label="Assigned density">350 <sub>p (kg/m³)</sub></td>
<td data-label="Characteristic head pull-through resistance">9.4 <sub>f (N/mm²)</sub></td>
<td data-label="Characteristic tensile resistance">36.0 <sub>f {kN}</sub></td>
<td data-label="Characteristic torsional resistance">45.0 <sub>f (N*m)</sub></td>
</tr>
</tbody>
</table>
I have created simple css table.
table {
border: 1px solid #ccc;
border-collapse: collapse;
margin: 0;
padding: 0;
width: 100%;
table-layout: fixed;
}
table caption {
font-size: 1.5em;
margin: .5em 0 .75em;
}
table tr {
background-color: white;
border: 1px solid #ddd;
padding: .35em;
}
table tr:hover {
background-color: #3b458e;
}
table th,
table td {
padding: .625em;
text-align: center;
}
table th {
font-size: .85em;
letter-spacing: .1em;
text-transform: uppercase;
}
#media screen and (max-width: 600px) {
table {
border: 0;
}
table caption {
font-size: 1.3em;
}
table thead {
border: none;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
table tr {
border-bottom: 3px solid #ddd;
display: block;
margin-bottom: .625em;
}
table td {
border-bottom: 1px solid #ddd;
display: block;
font-size: .8em;
text-align: right;
}
table td::before {
/*
* aria-label has no advantage, it won't be read inside a table
content: attr(aria-label);
*/
content: attr(data-label);
float: left;
font-weight: bold;
text-transform: uppercase;
}
table td:last-child {
border-bottom: 0;
}
}
<table>
<thead>
<tr>
<th scope="col">SKU</th>
<th scope="col">Image</th>
<th scope="col">EAN</th>
<th scope="col">Brand</th>
<th scope="col">Name</th>
<th scope="col">Size</th>
<th scope="col">Leadtime</th>
<th scope="col">MSRP</th>
<th scope="col">Price</th>
<th scope="col">Qty</th>
<th scope="col">Total</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Account">Visa - 3412</td>
<td data-label="Account">Visa - 3412</td>
<td data-label="Due Date">04/01/2016</td>
<td data-label="Amount">$1,190</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
<td data-label="Account">Visa - 3412</td>
<td data-label="Account">Visa - 3412</td>
<td data-label="Account">Visa - 3412</td>
<td data-label="Account">Visa - 3412</td>
<td data-label="Account">Visa - 3412</td>
<td data-label="Account">Visa - 3412</td>
</tr>
<tr>
<td scope="row" data-label="Account">Visa - 6076</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Amount">$2,443</td>
<td data-label="Period">02/01/2016 - 02/29/2016</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Due Date">03/01/2016</td>
</tr>
<tr>
<td scope="row" data-label="Account">Corporate AMEX</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Amount">$1,181</td>
<td data-label="Period">02/01/2016 - 02/29/2016</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Due Date">03/01/2016</td>
<td data-label="Due Date">03/01/2016</td>
</tr>
<tr>
<td scope="row" data-label="Acount">Visa - 3412</td>
<td data-label="Due Date">02/01/2016</td>
<td data-label="Amount">$842</td>
<td data-label="Period">01/01/2016 - 01/31/2016</td>
<td data-label="Due Date">02/01/2016</td>
<td data-label="Due Date">02/01/2016</td>
<td data-label="Due Date">02/01/2016</td>
<td data-label="Due Date">02/01/2016</td>
<td data-label="Due Date">02/01/2016</td>
<td data-label="Due Date">02/01/2016</td>
<td data-label="Due Date">02/01/2016</td>
<td data-label="Due Date">02/01/2016</td>
</tr>
</tbody>
</table>
Result:
How to removing the top, left and right border. (I want to leave only the bottom border)
Currently table head is hover, and td is hover:
head hover effect:
td hover effect:
I want delete head hover effect. I need only td hover effect. Can anyone help me correct this code?
Here you go.
What I changed:
removed border from everywhere, and just added border-bottom property to table row.
removed hover background from thead by adding table thead tr:hover with background:#fff;
table {
border-collapse: collapse;
margin: 0;
padding: 0;
width: 100%;
table-layout: fixed;
}
table caption {
font-size: 1.5em;
margin: .5em 0 .75em;
}
table tr {
background-color: white;
padding: .35em;
border-bottom: 1px #cdcdcd solid;
}
table tr:hover {
background-color: #3b458e;
}
table thead tr:hover {
background-color: #fff;
}
table th,
table td {
padding: .625em;
text-align: center;
}
table th {
font-size: .85em;
letter-spacing: .1em;
text-transform: uppercase;
}
#media screen and (max-width: 600px) {
table {
border: 0;
}
table caption {
font-size: 1.3em;
}
table thead {
border: none;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
table tr {
border-bottom: 3px solid #ddd;
display: block;
margin-bottom: .625em;
}
table td {
border-bottom: 1px solid #ddd;
display: block;
font-size: .8em;
text-align: right;
}
table td::before {
/*
* aria-label has no advantage, it won't be read inside a table
content: attr(aria-label);
*/
content: attr(data-label);
float: left;
font-weight: bold;
text-transform: uppercase;
}
table td:last-child {
border-bottom: 0;
}
}
I am learning css writing styles for an html table and I was wondering how I can remove the borders of the blank cell for the first row of my header, in addition to rounding the edges for the cells estimated amount and total.
I leave the html and css in addition to a thread of reproduction:
table {
border: 1px solid #ccc;
border-collapse: collapse;
margin: 0;
padding: 0;
width: 100%;
table-layout: fixed;
}
.blank {
background-color: #FFFFFF;
}
table tr {
background-color: #f8f8f8;
border: 2px solid #ddd;
padding: .35em;
}
table th,
table td {
padding: .625em;
text-align: center;
}
table th {
font-size: .85em;
letter-spacing: .1em;
text-transform: uppercase;
}
<table>
<thead>
<tr>
<th class="blank"></th>
<th colspan="2">estimated amount</th>
<th>total</th>
</tr>
<tr>
<th scope="col">Account</th>
<th scope="col">Expense</th>
<th scope="col">Income</th>
<th scope="col">Diff</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Expense">$3,190</td>
<td data-label="Income">$1,000</td>
<td data-label="Diff">$2,190</td>
</tr>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Expense">$5,000</td>
<td data-label="Income">$1,000</td>
<td data-label="Diff">$4,000</td>
</tr>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Expense">$7,000</td>
<td data-label="Income">$4,000</td>
<td data-label="Diff">$3,000</td>
</tr>
</tbody>
</table>
this is a tricky one because applying border-radius while having the value of border-collapse set to collapse will not work the way you wanted it to.
My solution for you is to create your borders using CSS like this :
table {
border-collapse: separate;
border-spacing: 0;
margin: 0;
padding: 0;
width: 100%;
table-layout: fixed;
}
th ,td {
border-right:2px solid #ddd;
border-bottom: 2px solid #ddd;
background-color: #f8f8f8;
padding: .35em;
}
#tr1 th:last-child {
border-top: 2px solid #ddd;
}
#tr1 th:nth-child(2) {
border-left: 2px solid #ddd;
border-top: 2px solid #ddd;
}
#tr2 th:first-child{
border-top: 2px solid #ddd;
}
#tr2 th:first-child{
border-left: 2px solid #ddd;
}
tr td:first-child{
border-left: 2px solid #ddd;
}
.blank {
background-color: #FFFFFF;
border: none;
}
.estimatedAmountClass {
border-top-left-radius: 40px;
}
.totalClass {
border-top-right-radius: 40px;
}
table th,
table td {
padding: .625em;
text-align: center;
}
table th {
font-size: .85em;
letter-spacing: .1em;
text-transform: uppercase;
}
<table >
<thead>
<tr id="tr1">
<th class="blank"></th>
<th class="estimatedAmountClass" colspan="2">estimated amount</th>
<th class="totalClass">total</th>
</tr>
<tr id="tr2">
<th scope="col">Account</th>
<th scope="col">Expense</th>
<th scope="col">Income</th>
<th scope="col">Diff</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Expense">$3,190</td>
<td data-label="Income">$1,000</td>
<td data-label="Diff">$2,190</td>
</tr>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Expense">$5,000</td>
<td data-label="Income">$1,000</td>
<td data-label="Diff">$4,000</td>
</tr>
<tr>
<td data-label="Account">Visa - 3412</td>
<td data-label="Expense">$7,000</td>
<td data-label="Income">$4,000</td>
<td data-label="Diff">$3,000</td>
</tr>
</tbody>
</table>
I would like to add a line break after each tr tag so there a gap between the next row of data. I have included what I thought should work but alas, no luck. Basically, if there are 10 rows of data separate each tr with a new line.
I would be grateful if someone could point out my error. many thanks
UPDATE: Screen grab to show exactly how I want the row spacing to appear. Notice the spacing at the bottm of each row.
table tr {
/* background: #f8f8f8;*/
/*border: 1px solid #ddd;*/
}
table th, table td {
text-align: left;
}
table th {
font-size: .85em;
letter-spacing: .1em;
text-transform: uppercase;
}
#media screen and (max-width: 600px) {
table {
border: 1px solid #eee;
border-radius: 5px !important;
}
table thead {
border: none;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
table tr {
/* border-bottom: 1px solid #ddd;*/
display: block;
/* margin-bottom: .625em;*/
}
table td {
/* border-bottom: 1px solid #ddd;*/
display: block;
font-size: .85em;
text-align: left;
/* margin-bottom: .625em;*/
}
table td:before {
content: attr(data-label);
float: left;
font-weight: bold;
text-transform: uppercase;
}
table td:last-child {
/* border-bottom: 0;*/
content: "" !important;
white-space: pre !important;
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<div class="container">
<table class="table table-striped">
<caption>
<h3>Caption</h3>
</caption>
<thead>
<tr>
<th scope="col">Due Date</th>
<th scope="col">Amount</th>
<th scope="col">Period</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Due Date" scope="row">04/01/2016</td>
<td data-label="Amount">$1,190</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
</tr>
<tr>
<td data-label="Due Date" scope="row">03/01/2016</td>
<td data-label="Amount">$2,443</td>
<td data-label="Period">02/01/2016 - 02/29/2016</td>
</tr>
<tr>
<td data-label="Due Date" scope="row">03/01/2016</td>
<td data-label="Amount">$1,181</td>
<td data-label="Period">02/01/2016 - 02/29/2016</td>
</tr>
<tr>
<td data-label="Due Date" scope="row">02/01/2016</td>
<td data-label="Amount">$842</td>
<td data-label="Period">01/01/2016 - 01/31/2016</td>
</tr>
</tbody>
</table>
</div>
I played a little with your code and ended up with this:
(I only added margin-bottom: 3em; in table tr td:last-child { … })
Feel free to comment if you want some modification.
table th,
table td {
text-align: left;
}
table th {
font-size: .85em;
letter-spacing: .1em;
text-transform: uppercase;
}
#media screen and (max-width: 600px) {
table {
border: 1px solid #eee;
border-radius: 5px !important;
}
table thead {
border: none;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
table tr {
display: block;
}
table td {
display: block;
font-size: .85em;
text-align: left;
}
table td:before {
content: attr(data-label);
float: left;
font-weight: bold;
text-transform: uppercase;
}
table tr td:last-child {
margin-bottom: 3em;
content: "" !important;
white-space: pre !important;
}
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js"></script>
<div class="container">
<table class="table table-striped">
<caption>
<h3>Caption</h3>
</caption>
<thead>
<tr>
<th scope="col">Due Date</th>
<th scope="col">Amount</th>
<th scope="col">Period</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Due Date" scope="row">04/01/2016</td>
<td data-label="Amount">$1,190</td>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
</tr>
<tr>
<td data-label="Due Date" scope="row">03/01/2016</td>
<td data-label="Amount">$2,443</td>
<td data-label="Period">02/01/2016 - 02/29/2016</td>
</tr>
<tr>
<td data-label="Due Date" scope="row">03/01/2016</td>
<td data-label="Amount">$1,181</td>
<td data-label="Period">02/01/2016 - 02/29/2016</td>
</tr>
<tr>
<td data-label="Due Date" scope="row">02/01/2016</td>
<td data-label="Amount">$842</td>
<td data-label="Period">01/01/2016 - 01/31/2016</td>
</tr>
</tbody>
</table>
</div>
Hope it helps.
If I'm understanding you correctly, you just want an empty line between each row. If that's the case then you'd want to target the td tag not the tr tag. You would add padding-bottom: 1em; to all rows and specify that the last row has padding-bottom: 0;. Try this solution:
table th, table td {
text-align: left;
}
table th {
font-size: .85em;
letter-spacing: .1em;
text-transform: uppercase;
}
#media screen and (max-width: 600px) {
table {
border: 1px solid #eee;
border-radius: 5px !important;
}
table thead {
border: none;
clip: rect(0 0 0 0);
height: 1px;
margin: -1px;
overflow: hidden;
padding: 0;
position: absolute;
width: 1px;
}
table tr {
display: block;
}
table td {
display: block;
font-size: .85em;
text-align: left;
padding-bottom: 1em;
}
table td:before {
content: attr(data-label);
float: left;
font-weight: bold;
text-transform: uppercase;
}
table td:last-child {
content: "" !important;
white-space: pre !important;
}
table tr:last-child td:last-child{
padding-bottom: 0;
}
}
<div class="container">
<table class="table table-striped">
<caption>
<h3>Caption</h3>
</caption>
<thead>
<tr>
<th scope="col">Due Date</th>
<th scope="col">Amount</th>
<th scope="col">Period</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Due Date" scope="row">04/01/2016</td>
<td data-label="Amount">$1,190</td>
<br/>
<td data-label="Period">03/01/2016 - 03/31/2016</td>
</tr>
<tr>
<td data-label="Due Date" scope="row">03/01/2016</td>
<td data-label="Amount">$2,443</td>
<td data-label="Period">02/01/2016 - 02/29/2016</td>
</tr>
<tr>
<td data-label="Due Date" scope="row">03/01/2016</td>
<td data-label="Amount">$1,181</td>
<td data-label="Period">02/01/2016 - 02/29/2016</td>
</tr>
<tr>
<td data-label="Due Date" scope="row">02/01/2016</td>
<td data-label="Amount">$842</td>
<td data-label="Period">01/01/2016 - 01/31/2016</td>
</tr>
</tbody>
</table>
</div>
Olivier answer is good, but I think border-spacing is more appropriate here. Padding adds blank space INTO the cells which might have unwanted visual consequences (e.g. when border is displayed).
From what you asked, you probably want the empty space BETWEEN the cells. I would recommend something like this
table {
border-collapse: separate;
border-spacing: 0 10px; // or 0.85em but i would recommend using pixels here
}
The 0 is for horizontal spacing (which you don't want), 10px is for vertical spacing (thats the space between rows).
This question already has answers here:
Removing unwanted table cell borders with CSS
(8 answers)
Closed 6 years ago.
table {
border: solid 1px #eee;
text-align: right;
}
tr,
td,
th {
padding: 0;
margin: 0;
border: none;
}
th,
td {
width: 90px;
height: 24px;
line-height: 24px;
padding: 0;
}
th {
background-color: #f4f4f4;
}
.first-col {
text-align: left;
}
<table class="satisfaction">
<tr>
<th class="first-col">Kepuasan</th>
<th>1 bulan</th>
<th>6 bulan</th>
<th>12 bulan</th>
</tr>
<tr>
<td class="first-col"><span><img class="svg emo emo-smile" src="img/icon/emoticon-happy.svg">Positif</span>
</td>
<td>9393</td>
<td>9393</td>
<td>9393</td>
</tr>
<tr>
<td class="first-col"><span><img class="svg emo emo-neutral" src="img/icon/emoticon-neutral.svg">Netral</span>
</td>
<td>93</td>
<td>93</td>
<td>93</td>
</tr>
<tr class="last-row">
<td class="first-col"><span><img class="svg emo emo-frown" src="img/icon/emoticon-sad.svg">Negatif</span>
</td>
<td>39</td>
<td>39</td>
<td>39</td>
</tr>
</table>
I made a table and I keep seeing this white separator on the first row.
I already done make all margin and padding to zero but it doesn't work. So far this is my styling
table {
border: solid 1px #eee;
text-align: right;
}
tr, td, th {
padding: 0;
margin: 0;
border: none;
}
th, td {
width: 90px;
height: 24px;
line-height: 24px;
padding: 0;
}
th {
background-color: #f4f4f4;
}
.first-col {
text-align: left;
}
Is there anything I'm missing out? Any help appreciated!
Looking at your posted CSS it seems likely that the 'border' is appearing because you haven't collapsed the cell-borders; so with that in mind I'd suggest you add the rule:
border-collapse: collapse;
to the CSS rules for the table element:
table {
border-collapse: collapse;
border: solid 1px #eee;
text-align: right;
}
table {
border-collapse: collapse;
border: solid 1px #eee;
text-align: right;
}
tr,
td,
th {
padding: 0;
margin: 0;
border: none;
}
th,
td {
width: 90px;
height: 24px;
line-height: 24px;
padding: 0;
}
th {
background-color: #f4f4f4;
}
.first-col {
text-align: left;
}
<table class="satisfaction">
<tr>
<th class="first-col">Kepuasan</th>
<th>1 bulan</th>
<th>6 bulan</th>
<th>12 bulan</th>
</tr>
<tr>
<td class="first-col"><span><img class="svg emo emo-smile" src="img/icon/emoticon-happy.svg">Positif</span>
</td>
<td>9393</td>
<td>9393</td>
<td>9393</td>
</tr>
<tr>
<td class="first-col"><span><img class="svg emo emo-neutral" src="img/icon/emoticon-neutral.svg">Netral</span>
</td>
<td>93</td>
<td>93</td>
<td>93</td>
</tr>
<tr class="last-row">
<td class="first-col"><span><img class="svg emo emo-frown" src="img/icon/emoticon-sad.svg">Negatif</span>
</td>
<td>39</td>
<td>39</td>
<td>39</td>
</tr>
</table>
References:
border-collapse.