I have the table shown below; what I want is to insert an image next to the table in my pdf view. I am using domPDF.
I try to use display inline-block but domPDF doesn't support display inline.
table {
width: 100%;
border-collapse: collapse;
border-spacing: 0;
margin-bottom: 20px;
}
table th,
table td {
padding: 20px;
background: #EEEEEE;
text-align: center;
border-bottom: 1px solid #FFFFFF;
}
table th {
white-space: nowrap;
font-weight: normal;
}
table td {
text-align: right;
}
table td h3 {
color: #ab5401;
font-size: 1.2em;
font-weight: normal;
margin: 0 0 0.2em 0;
}
table .no {
color: #FFFFFF;
font-size: 1.6em;
background: #ad9c82;
}
table .desc {
text-align: left;
}
table .total .total-div {
text-decoration: line-through;
}
table .total {
background: #ad9c82;
color: #FFFFFF;
}
table td.total {
font-size: 1.2em;
}
table tbody tr:last-child td {
border: none;
}
table tfoot td {
padding: 10px 20px;
background: #FFFFFF;
border-bottom: none;
font-size: 1.2em;
white-space: nowrap;
border-top: 1px solid #AAAAAA;
}
table tfoot tr:first-child td {
border-top: none;
}
table tfoot tr:last-child td {
color: #ab5401;
font-size: 1.4em;
border-top: 1px solid #ab5401;
}
table tfoot tr td:first-child {
border: none;
}
<table border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th class="no">#</th>
<th class="desc">DESCRIPTION</th>
<th class="total">TOTAL</th>
</tr>
</thead>
<tbody>
<tr>
<td class="no">01</td>
<td class="desc">
<h3>Website Design</h3>Creating a recognizable design solution based on the company's existing visual identity</td>
<td class="total">$1,200.00</td>
</tr>
<tr>
<td class="no">02</td>
<td class="desc">
<h3>Website Development</h3>Developing a Content Management System-based Website</td>
<td class="total">$3,200.00</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2"></td>
<td colspan="2">SUBTOTAL</td>
<td>$5,200.00</td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2">TAX 25%</td>
<td>$1,300.00</td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2">GRAND TOTAL</td>
<td>$6,500.00</td>
</tr>
</tfoot>
</table>
While the image for placeholder is the following:
<img src="https://picsum.photos/200" alt="Image example">
I tried to add it but it is always placed under the table, not next to it as I want.
Try Adding good old floats.
table {
width: 100%;
border-collapse: collapse;
border-spacing: 0;
margin-bottom: 20px;
}
table th,
table td {
padding: 20px;
background: #EEEEEE;
text-align: center;
border-bottom: 1px solid #FFFFFF;
}
table th {
white-space: nowrap;
font-weight: normal;
}
table td {
text-align: right;
}
table td h3 {
color: #ab5401;
font-size: 1.2em;
font-weight: normal;
margin: 0 0 0.2em 0;
}
table .no {
color: #FFFFFF;
font-size: 1.6em;
background: #ad9c82;
}
table .desc {
text-align: left;
}
table .total .total-div {
text-decoration: line-through;
}
table .total {
background: #ad9c82;
color: #FFFFFF;
}
table td.total {
font-size: 1.2em;
}
table tbody tr:last-child td {
border: none;
}
table tfoot td {
padding: 10px 20px;
background: #FFFFFF;
border-bottom: none;
font-size: 1.2em;
white-space: nowrap;
border-top: 1px solid #AAAAAA;
}
table tfoot tr:first-child td {
border-top: none;
}
table tfoot tr:last-child td {
color: #ab5401;
font-size: 1.4em;
border-top: 1px solid #ab5401;
}
table tfoot tr td:first-child {
border: none;
}
<div style="width: 65%;float:left;">
<table border="0" cellspacing="0" cellpadding="0">
<thead>
<tr>
<th class="no">#</th>
<th class="desc">DESCRIPTION</th>
<th class="total">TOTAL</th>
</tr>
</thead>
<tbody>
<tr>
<td class="no">01</td>
<td class="desc">
<h3>Website Design</h3>Creating a recognizable design solution based on the company's existing visual identity</td>
<td class="total">$1,200.00</td>
</tr>
<tr>
<td class="no">02</td>
<td class="desc">
<h3>Website Development</h3>Developing a Content Management System-based Website</td>
<td class="total">$3,200.00</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="2"></td>
<td colspan="2">SUBTOTAL</td>
<td>$5,200.00</td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2">TAX 25%</td>
<td>$1,300.00</td>
</tr>
<tr>
<td colspan="2"></td>
<td colspan="2">GRAND TOTAL</td>
<td>$6,500.00</td>
</tr>
</tfoot>
</table>
</div>
<div style="width: 30%;float:left;">
<img src="https://picsum.photos/200" alt="Image example" style="width: 100%;">
</div>
Related
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.
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>
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>
I have created a table however I cannot get the <thead>s to line up with the <tbody>s.
The table is responsive and works as I want it to when resized, however it's the initial screen size that is the issue.
I have added float:left to the <thead>s so they align properly instead of overlapping each other and would like the table data to a-line in the same way.
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: #f8f8f8;
border: 1px solid #ddd;
padding: .35em;
}
table th,
table td {
padding: .625em;
text-align: center;
}
table td {
font-size: 0.60em;
}
table th {
font-size: .60em;
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-wrapper {
position: relative;
}
#table-scroll {
overflow: auto;
}
#table-wrapper table {
width: 100%;
}
#table-wrapper table * {
color: black;
font-size: 12px;
}
#table-wrapper table thead th .text {
text-align: center;
}
}
<div class="col-12 offset-0">
<div style="overflow-x:auto">
<div id="table-wrapper">
<div id="table-scroll">
<table class="table table-striped" border="0" cellspacing="0" cellpadding="0" align="center">
<h4>Success Stream</h4>
<thead style="float:left">
<tr>
<th scope="col">Year</th>
<th scope="col">{{n1}}'s age</th>
<th scope="col">{{n2}}'s age</th>
<th scope="col">Income</th>
<th scope="col">Personal Contribution to Pension</th>
<th scope="col">Company Contribution to Pension</th>
<th scope="col">Personal Contribution to ISA</th>
<th scope="col">Expenses</th>
<th scope="col">Cash Flow</th>
<th scope="col">Growth of Pension</th>
<th scope="col">Growth of ISA</th>
<th scope="col">Growth of Other</th>
<th scope="col">Withdrawals from Pension</th>
<th scope="col">Withdrawals from ISA</th>
<th scope="col">Withdrawals from Other</th>
<th scope="col">Pension Total</th>
<th scope="col">ISA Total</th>
<th scope="col">Other Total</th>
<th scope="col">Full Total</th>
</tr>
</thead>
<tbody>
<tr>
<td data-label="Year"> 2018</td>
<td data-label="{{n1}}'s age">55</td>
<td data-label="{{n2}}'s age">55</td>
<td data-label="Income">57,000</td>
<td data-label="Personal Contribution to Pension">5,000</td>
<td data-label="Company Contribution to Pension">0</td>
<td data-label="Personal Contribution to ISA">0</td>
<td data-label="Expenses">50,500</td>
<td data-label="Cash Flow">1,500</td>
<td data-label="Growth of Pension">57,737</td>
<td data-label="Growth of ISA">0</td>
<td data-label="Growth of Other">0</td>
<td data-label="Withdrawals from Pension">0</td>
<td data-label="Withdrawals from ISA">0</td>
<td data-label="Withdrawals from Other">0</td>
<td data-label="Pension Total">862,737</td>
<td data-label="ISA Total">1</td>
<td data-label="Other Total">1,501</td>
<td data-label="Full Total">864,239</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
Instead of using float:left for thead just change
table {
table-layout: fixed;
}
to
table {
table-layout: auto;
}
I'm new to CSS and HTML and I'm trying to vertically center some text in a table header. At the moment the text is aligned with the top of the table cell. I was unsuccessful with vertical-align: middle;, and the only solution seems to be to add padding-top to match the space underneath the text. However this is not the best solution because I would like to have the text fit snugly within the table cell. Any ideas are appreciated.
body {
font-size: 18px;
font-family: 'Open Sans', sans-serif;
text-align: center;
color: black;
background-size: 100%;
padding:0;
}
.mytable {
border: solid 1px #DDEEEE;
border-collapse: collapse;
border-spacing: 0;
width: 80%;
}
.mytable thead th {
background-color: #DDEFEF;
border: solid 1px #DDEEEE;
color: #336B6B;
/*padding: 30px;*/
text-align: center;
vertical-align: middle;
}
.mytable tbody td {
border: solid 1px #DDEEEE;
color: #333;
padding: 30px;
}
<div id="myWebPage" style="display:block">
<br><br><br><br>
<h3>Page title here</h3><br><br><br>
<table class="mytable" align="center">
<thead>
<tr>
<th><u>Resource</u><br><br><br></th>
<th><u>Contact</u><br><br><br></th>
</tr>
</thead>
<tbody>
<tr>
<th align="left">Resource 1<br><br></th>
<th align="left" width=35%;>999-999-9999<br> <br></th>
</tr>
<tr>
<th align="left">Resource 2<br><br></th>
<th align="left">888-888-8888<br><br></th>
</tr>
<tr>
<th align="left">Resource 3<br><br></th>
<th align="left" width=35%;>777-777-7777<br> <br></th>
</tr>
</tbody>
</table>
</div>
You have done it right in your CSS, just remove your <br> tags. E.g.
<th><u>Resource</u></th>
The vertical alignment won't work whilst you're manually inserting lines under your headings.
Full example
body {
font-size: 18px;
font-family: 'Open Sans', sans-serif;
text-align: center;
color: black;
background-size: 100%;
padding:0;
}
.mytable {
border: solid 1px #DDEEEE;
border-collapse: collapse;
border-spacing: 0;
width: 80%;
}
.mytable thead th {
background-color: #DDEFEF;
border: solid 1px #DDEEEE;
color: #336B6B;
/*padding: 30px;*/
text-align: center;
vertical-align: middle;
}
.mytable tbody td {
border: solid 1px #DDEEEE;
color: #333;
padding: 30px;
}
<div id="myWebPage" style="display:block">
<br><br><br><br>
<h3>Page title here</h3><br><br><br>
<table class="mytable" align="center">
<thead>
<tr>
<th><u>Resource</u></th>
<th><u>Contact</u></th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Resource 1<br><br></td>
<td align="left" width=35%;>999-999-9999<br> <br></td>
</tr>
<tr>
<td align="left">Resource 2<br><br></td>
<td align="left">888-888-8888<br><br></td>
</tr>
<tr>
<td align="left">Resource 3<br><br></td>
<td align="left" width=35%;>777-777-7777<br> <br></td>
</tr>
</tbody>
</table>
</div>
Try like this , why are you put <br> and <td> to <th>
Table <td> The elements are the data containers of the table.
HTML Tag is
A line break is marked up as follows:
This text contains<br>a line break.
body {
font-size: 18px;
font-family: 'Open Sans', sans-serif;
text-align: center;
color: black;
background-size: 100%;
padding:0;
}
.mytable {
border: solid 1px #DDEEEE;
border-collapse: collapse;
border-spacing: 0;
width: 80%;
}
.mytable thead th {
background-color: #DDEFEF;
border: solid 1px #DDEEEE;
color: #336B6B;
/*padding: 30px;*/
text-align: center;
vertical-align: middle;
}
.mytable tbody td {
border: solid 1px #DDEEEE;
color: #333;
padding: 30px;
}
<h3>Page title here</h3>
<table class="mytable" align="center">
<thead>
<tr>
<th><u>Resource</u></th>
<th><u>Contact</u></th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Resource 1</td>
<td align="left" width=35%;>999-999-9999</td>
</tr>
<tr>
<td align="left">Resource 2</td>
<td align="left">888-888-8888</td>
</tr>
<tr>
<td align="left">Resource 3</td>
<td align="left" width=35%;>777-777-7777</td>
</tr>
</tbody>
</table>
learn more about html table https://www.w3schools.com/html/html_tables.asp
Define a height value for the th elements
Define an explicit (absolute) height for your table header cells (th) using length unit values (e.g: 65px), then declare the vertical-align rule on these elements.
Code Snippet Demonstration:
body {
font-size: 18px;
font-family: 'Open Sans', sans-serif;
text-align: center;
color: black;
background-size: 100%;
padding: 0;
}
.mytable {
border: solid 1px #DDEEEE;
border-collapse: collapse;
border-spacing: 0;
width: 80%;
}
.mytable thead th {
background-color: #DDEFEF;
border: solid 1px #DDEEEE;
color: #336B6B;
/*padding: 30px;*/
text-align: center;
vertical-align: middle;
/* additional */
height: 65px;
}
.mytable tbody td {
border: solid 1px #DDEEEE;
color: #333;
padding: 30px;
}
<div id="myWebPage" style="display:block">
<br><br><br><br>
<h3>Page title here</h3><br><br><br>
<table class="mytable" align="center">
<thead>
<tr>
<th><u>Resource</u></th>
<th><u>Contact</u></th>
</tr>
</thead>
<tbody>
<tr>
<th align="left">Resource 1<br><br></th>
<th align="left" width=35%;>999-999-9999<br> <br></th>
</tr>
<tr>
<th align="left">Resource 2<br><br></th>
<th align="left">888-888-8888<br><br></th>
</tr>
<tr>
<th align="left">Resource 3<br><br></th>
<th align="left" width=35%;>777-777-7777<br> <br></th>
</tr>
</tbody>
</table>
</div>
Don't use <br> tags for layout - that's a no-go! It will mess up whatever you try concerning vertical alignment and top/bottom padding and margins, like in the code in your question.
Erase them all and use top and bottom padding instead.
If still needed, use vertical-align, but in most cases you won't need it. And use the td tag for cells in the tbody, not th.
body {
font-size: 18px;
font-family: 'Open Sans', sans-serif;
text-align: center;
color: black;
background-size: 100%;
padding:0;
}
#myWebPage > h3 {
padding: 40px 0;
}
.mytable {
border: solid 1px #DDEEEE;
border-collapse: collapse;
border-spacing: 0;
width: 80%;
}
.mytable thead th {
background-color: #DDEFEF;
border: solid 1px #DDEEEE;
color: #336B6B;
padding: 30px 0;
/*padding: 30px;*/
text-align: center;
vertical-align: middle;
}
.mytable tbody td {
border: solid 1px #DDEEEE;
color: #333;
padding: 30px;
}
<div id="myWebPage">
<h3>Page title here</h3>
<table class="mytable" align="center">
<thead>
<tr>
<th><u>Resource</u></th>
<th><u>Contact</u></th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Resource 1</td>
<td align="left" width=35%;>999-999-9999</td>
</tr>
<tr>
<td align="left">Resource 2</td>
<td align="left">888-888-8888</td>
</tr>
<tr>
<td align="left">Resource 3</td>
<td align="left" width=35%;>777-777-7777</td>
</tr>
</tbody>
</table>
</div>