Unwanted table cell border [duplicate] - html

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.

Related

I can't change row's background color in table

I can't change rows' background-color; I'd like to have one row red.
Here is my code:
table.cennik-table {
font-size: 20px;
border: 3px solid #555555;
width: 80%;
height: auto;
text-align: center;
border-collapse: collapse;
margin: 0 auto;
}
table.cennik-table th {
font-size: 22px;
background-color: #888888;
}
table.cennik-table td {
padding: 0.7rem;
}
table.cennik-table tr.rowB {
background-color: red;
}
<div>
<table class="cennik-table">
<tr>
<th>Ilość wejść</th>
<th>Zajęcia grupowe</th>
<th>Treningi personalne</th>
</tr>
<tr class="rowB">
<td>1x tydzień</td>
<td>20zł</td>
<td rowspan="4">50zł</td>
</tr>
<tr class="rowA">
<td>2x tydzień</td>
<td>60zł</td>
</tr>
<tr class="rowB">
<td>3x tydzień</td>
<td>110zł</td>
</tr>
<tr class="rowA">
<td>OPEN</td>
<td>160zł</td>
</tr>
</table>
</div>
I'm a beginner so I could have made some simple mistakes.

How do I make this nutrition label display properly with HTML and CSS

I'm designing a site that is going to display a nutrition label on it with dynamically filled nutritional information. I found some free code for a nutrition label online: https://codepen.io/chriscoyier/pen/egHEK
but for some reason my label does not come out like the one in the example.
This is how my label displays: https://i.imgur.com/IEJsCq6.jpg
This is how I want my label to display: https://i.imgur.com/KgMCbJ1.jpg
I'm missing some lines and some of the formatting isn't correct. I believe it has to do with the #import "compass/css3"; not working properly.
Does anyone know how I can get my label to display exactly like the one from codepen? Thanks.
<style>
#import "compass/css3";
.image {
width: 250px;
float: left;
margin: 20px;
}
body {
font-size: small;
line-height: 1.4;
}
p {
margin: 0;
}
.performance-facts {
border: 1px solid black;
margin: 20px;
float: left;
width: 280px;
padding: 0.5rem;
table {
border-collapse: collapse;
}
}
.performance-facts__title {
font-weight: bold;
font-size: 2rem;
margin: 0 0 0.25rem 0;
}
.performance-facts__header {
border-bottom: 10px solid black;
padding: 0 0 0.25rem 0;
margin: 0 0 0.5rem 0;
p {
margin: 0;
}
}
.performance-facts__table {
width: 100%;
thead tr {
th, td {
border: 0;
}
}
th, td {
font-weight: normal;
text-align: left;
padding: 0.25rem 0;
border-top: 1px solid black;
white-space: nowrap;
}
td {
&:last-child {
text-align: right;
}
}
.blank-cell {
width: 1rem;
border-top: 0;
}
.thick-row {
th, td {
border-top-width: 5px;
}
}
}
.small-info {
font-size: 0.7rem;
}
.performance-facts__table--small {
#extend .performance-facts__table;
border-bottom: 1px solid #999;
margin: 0 0 0.5rem 0;
thead {
tr {
border-bottom: 1px solid black;
}
}
td {
&:last-child {
text-align: left;
}
}
th, td {
border: 0;
padding: 0;
}
}
.performance-facts__table--grid {
#extend .performance-facts__table;
margin: 0 0 0.5rem 0;
td {
&:last-child {
text-align: left;
&::before {
content: "•";
font-weight: bold;
margin: 0 0.25rem 0 0;
}
}
}
}
.text-center {
text-align: center;
}
.thick-end {
border-bottom: 10px solid black;
}
.thin-end {
border-bottom: 1px solid black;
}
</style>
<html>
<img src="https://s.cdpn.io/3/NutritionFacts.gif" class="image">
<section class="performance-facts">
<header class="performance-facts__header">
<h1 class="performance-facts__title">Nutrition Facts</h1>
<p>Serving Size 1/2 cup (about 82g)
<p>Serving Per Container 8</p>
</header>
<table class="performance-facts__table">
<thead>
<tr>
<th colspan="3" class="small-info">
Amount Per Serving
</th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="2">
<b>Calories</b>
200
</th>
<td>
Calories from Fat
130
</td>
</tr>
<tr class="thick-row">
<td colspan="3" class="small-info">
<b>% Daily Value*</b>
</td>
</tr>
<tr>
<th colspan="2">
<b>Total Fat</b>
14g
</th>
<td>
<b>22%</b>
</td>
</tr>
<tr>
<td class="blank-cell">
</td>
<th>
Saturated Fat
9g
</th>
<td>
<b>22%</b>
</td>
</tr>
<tr>
<td class="blank-cell">
</td>
<th>
Trans Fat
0g
</th>
<td>
</td>
</tr>
<tr>
<th colspan="2">
<b>Cholesterol</b>
55mg
</th>
<td>
<b>18%</b>
</td>
</tr>
<tr>
<th colspan="2">
<b>Sodium</b>
40mg
</th>
<td>
<b>2%</b>
</td>
</tr>
<tr>
<th colspan="2">
<b>Total Carbohydrate</b>
17g
</th>
<td>
<b>6%</b>
</td>
</tr>
<tr>
<td class="blank-cell">
</td>
<th>
Dietary Fiber
1g
</th>
<td>
<b>4%</b>
</td>
</tr>
<tr>
<td class="blank-cell">
</td>
<th>
Sugars
14g
</th>
<td>
</td>
</tr>
<tr class="thick-end">
<th colspan="2">
<b>Protein</b>
3g
</th>
<td>
</td>
</tr>
</tbody>
</table>
<table class="performance-facts__table--grid">
<tbody>
<tr>
<td colspan="2">
Vitamin A
10%
</td>
<td>
Vitamin C
0%
</td>
</tr>
<tr class="thin-end">
<td colspan="2">
Calcium
10%
</td>
<td>
Iron
6%
</td>
</tr>
</tbody>
</table>
<p class="small-info">* Percent Daily Values are based on a 2,000 calorie diet. Your daily values may be higher or lower depending on your calorie needs:</p>
<table class="performance-facts__table--small small-info">
<thead>
<tr>
<td colspan="2"></td>
<th>Calories:</th>
<th>2,000</th>
<th>2,500</th>
</tr>
</thead>
<tbody>
<tr>
<th colspan="2">Total Fat</th>
<td>Less than</td>
<td>65g</td>
<td>80g</td>
</tr>
<tr>
<td class="blank-cell"></td>
<th>Saturated Fat</th>
<td>Less than</td>
<td>20g</td>
<td>25g</td>
</tr>
<tr>
<th colspan="2">Cholesterol</th>
<td>Less than</td>
<td>300mg</td>
<td>300 mg</td>
</tr>
<tr>
<th colspan="2">Sodium</th>
<td>Less than</td>
<td>2,400mg</td>
<td>2,400mg</td>
</tr>
<tr>
<th colspan="3">Total Carbohydrate</th>
<td>300g</td>
<td>375g</td>
</tr>
<tr>
<td class="blank-cell"></td>
<th colspan="2">Dietary Fiber</th>
<td>25g</td>
<td>30g</td>
</tr>
</tbody>
</table>
<p class="small-info">
Calories per gram:
</p>
<p class="small-info text-center">
Fat 9
•
Carbohydrate 4
•
Protein 4
</p>
</section>
</html>
You are embedding scss stylesheet in the html, you can't directly insert an SCSS (Sassy CSS) file into your HTML. That's because SASS is a superset (or so-called preprocessor or extension) of CSS3's syntax, which is NOT supported by web browsers.
Go to your codepen (https://codepen.io/chriscoyier/pen/egHEK), in the css section, there is a dropdown which gives option to compile scss to the css, (view compiled css). Click on that, you will get the final compiled css as below:
#charset "UTF-8";
.image {
width: 250px;
float: left;
margin: 20px;
}
body {
font-size: small;
line-height: 1.4;
}
p {
margin: 0;
}
.performance-facts {
border: 1px solid black;
margin: 20px;
float: left;
width: 280px;
padding: 0.5rem;
}
.performance-facts table {
border-collapse: collapse;
}
.performance-facts__title {
font-weight: bold;
font-size: 2rem;
margin: 0 0 0.25rem 0;
}
.performance-facts__header {
border-bottom: 10px solid black;
padding: 0 0 0.25rem 0;
margin: 0 0 0.5rem 0;
}
.performance-facts__header p {
margin: 0;
}
.performance-facts__table, .performance-facts__table--small, .performance-facts__table--grid {
width: 100%;
}
.performance-facts__table thead tr th, .performance-facts__table--small thead tr th, .performance-facts__table--grid thead tr th,
.performance-facts__table thead tr td,
.performance-facts__table--small thead tr td,
.performance-facts__table--grid thead tr td {
border: 0;
}
.performance-facts__table th, .performance-facts__table--small th, .performance-facts__table--grid th,
.performance-facts__table td,
.performance-facts__table--small td,
.performance-facts__table--grid td {
font-weight: normal;
text-align: left;
padding: 0.25rem 0;
border-top: 1px solid black;
white-space: nowrap;
}
.performance-facts__table td:last-child, .performance-facts__table--small td:last-child, .performance-facts__table--grid td:last-child {
text-align: right;
}
.performance-facts__table .blank-cell, .performance-facts__table--small .blank-cell, .performance-facts__table--grid .blank-cell {
width: 1rem;
border-top: 0;
}
.performance-facts__table .thick-row th, .performance-facts__table--small .thick-row th, .performance-facts__table--grid .thick-row th,
.performance-facts__table .thick-row td,
.performance-facts__table--small .thick-row td,
.performance-facts__table--grid .thick-row td {
border-top-width: 5px;
}
.small-info {
font-size: 0.7rem;
}
.performance-facts__table--small {
border-bottom: 1px solid #999;
margin: 0 0 0.5rem 0;
}
.performance-facts__table--small thead tr {
border-bottom: 1px solid black;
}
.performance-facts__table--small td:last-child {
text-align: left;
}
.performance-facts__table--small th,
.performance-facts__table--small td {
border: 0;
padding: 0;
}
.performance-facts__table--grid {
margin: 0 0 0.5rem 0;
}
.performance-facts__table--grid td:last-child {
text-align: left;
}
.performance-facts__table--grid td:last-child::before {
content: "•";
font-weight: bold;
margin: 0 0.25rem 0 0;
}
.text-center {
text-align: center;
}
.thick-end {
border-bottom: 10px solid black;
}
.thin-end {
border-bottom: 1px solid black;
}
Embed this css in your html, it should work. Kindly increase .performance-facts width to 300 from 280, so it will look nice.

CSS Table with custom borders

I'm stuck with a simple table design as i'm from backend I need a table like this
What I have right now
table {
border-collapse: collapse;
width: 100%;
}
tr {
border: none;
}
.first{
width: 40%;
font-family: Quasimoda;
font-size: 0.75em;
color: #1D1D1E;
}
.middle{
width: 60%;
font-family: Quasimoda;
font-size: 0.75em;
color: #1D1D1E;
}
.last{
width: 40%;
font-family: Quasimoda;
font-size: 0.75em;
color: #1D1D1E;
}
td {
border-bottom: 1px solid #ddd;
border-top: 1px solid #ddd;
padding: 10px;
}
<table>
<tr>
<td class="University">January</td>
<td class="middle ">the progress bar will be placed here </td>
<td class="last">870</td>
</tr>
<tr>
<td class="first">January</td>
<td class="middle ">the progress bar will be placed here </td>
<td class="last">560</td>
</tr>
</table>
Please help. I have tried with multiple html table attributes all gone in vain.
Set the thead tr element bottom border, and the right border of the .first element:
table {
border-collapse: collapse;
width: 100%;
}
th {
text-align: left;
border-bottom: 1px solid #ddd;
}
td {
padding: 10px;
font-family: Quasimoda;
font-size: 0.75em;
color: #1D1D1E;
}
.first {
border-right: 1px solid #ddd;
}
.middle {
width: 100%;
}
<table>
<thead>
<tr>
<th colspan="3">Unique values:</th>
</tr>
</thead>
<tbody>
<tr>
<td class="first">January</td>
<td class="middle ">the progress bar will be placed here </td>
<td class="last">870</td>
</tr>
<tr>
<td class="first">January</td>
<td class="middle ">the progress bar will be placed here </td>
<td class="last">560</td>
</tr>
</tbody>
</table>
Actually, your picture is not that clear.
I was not clear where you want border actually.
But I try to do this, Run the code snippet and have a look, and let me know if this works for you or not.
.colspan2border
{
border-collapse: collapse;
border-bottom: 1px solid red;
}
.rightBorder
{
border-collapse: collapse;
border-right: 1px solid red;
}
.pr-left1
{
padding-left: 1rem;
}
table
{
border-collapse: collapse;
}
tr
{
border: none;
}
<table>
<tr colspan="2" class='colspan2border'><td>Unique values:</td></tr>
<tr>
<td class="rightBorder pr-left1">University</td>
<td>870</td>
</tr>
<tr>
<td class="rightBorder pr-left1">Custom</td>
<td>560</td>
</tr>
</table>

Colgroup and Col aren't visible on desktop

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.

How to place image over this table and make the position responsive

I have placed the image but it breaks when we resize the window.
I want it in the center of the first column which is description below the email service.
I want it to remain in the center all the time.
I have given the td position relative and made the image absolute position. Its relative to the td................................
* {
font-family: sans-serif;
}
table{
width: 100%;
border: 1px solid #edf2fc;
border-collapse: collapse;
margin-top: 30px;
}
table th {
padding: 11px 6px 11px 6px;
word-break: break-all;
background: #413fa4;
color: #fff;
text-align: center;
}
tr td {
border: 1px solid #cbdaf1;
}
table tbody td {
text-align: center;
padding: 33px 0 33px 0;
word-break: break-all;
font-size: 18px;
}
tfoot tr td {
padding-top: 4px;
padding-bottom: 4px;
}
tfoot tr td:first-child{
padding-right: 22px;
}
.gray {
background-color: lightgray
}
<table width="100%">
<thead style="background-color: lightgray;">
<tr>
<th>Description</th>
<th>Cost</th>
</tr>
</thead>
<tbody>
<tr>
<td style="position: relative">Email Service
<img style="position: absolute; left: 300px; top: 70px;" src="https://image.shutterstock.com/image-vector/paid-thank-you-grunge-rubber-260nw-564254104.jpg"width=130px;>
</td>
<td align="center">1400.00</td>
</tr>
</tbody>
<tfoot>
<tr>
<td align="right">Subtotal</td>
<td align="center">1635.00</td>
</tr>
<tr>
<td align="right">Tax</td>
<td align="center">294.3</td>
</tr>
<tr>
<td align="right">Discount</td>
<td align="center">294.3</td>
</tr>
<tr>
<td align="right">Total</td>
<td align="center" class="gray">$ 1929.3</td>
</tr>
</tfoot>
</table>
Wrap the text and the image inside a div with a flex box property, and then you can center it as you like
* {
font-family: sans-serif;
}
table{
width: 100%;
border: 1px solid #edf2fc;
border-collapse: collapse;
margin-top: 30px;
}
table th {
padding: 11px 6px 11px 6px;
word-break: break-all;
background: #413fa4;
color: #fff;
text-align: center;
}
tr td {
border: 1px solid #cbdaf1;
}
table tbody td {
text-align: center;
padding: 33px 0 33px 0;
word-break: break-all;
font-size: 18px;
}
tfoot tr td {
padding-top: 4px;
padding-bottom: 4px;
}
tfoot tr td:first-child{
padding-right: 22px;
}
.gray {
background-color: lightgray
}
.flex-b {
display:flex;
align-items:center;
justify-content:center;
}
<table width="100%">
<thead style="background-color: lightgray;">
<tr>
<th>Description</th>
<th>Cost</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="flex-b">
<span>Email Service</span>
<img src="https://image.shutterstock.com/image-vector/paid-thank-you-grunge-rubber-260nw-564254104.jpg"width=130px;>
</div>
</td>
<td align="center">1400.00</td>
</tr>
</tbody>
<tfoot>
<tr>
<td align="right">Subtotal</td>
<td align="center">1635.00</td>
</tr>
<tr>
<td align="right">Tax</td>
<td align="center">294.3</td>
</tr>
<tr>
<td align="right">Discount</td>
<td align="center">294.3</td>
</tr>
<tr>
<td align="right">Total</td>
<td align="center" class="gray">$ 1929.3</td>
</tr>
</tfoot>
</table>