Unable to left align the div items - html

I have this table where I have some items inside one of the TDs. I need them to be centerd but left-aligned.
Right now the td looks like this:
$12.95 is slightly to the left.
I want it to look like this:
Here's the code:
table {
border-collapse: collapse;
}
table tr {
text-align: center;
margin-bottom: 1px;
}
table td {
border: 1px solid #ddd;
font-size: 13px;
padding: 10px 0;
height: 90px;
width: 100px;
}
table tr td:last-child{
width: 200px;
}
.price-container .price-package-one,
.price-container .price-package-two,
.price-container .price-package-three {
display: flex;
justify-content: center;
margin-bottom: 10px;
}
.price-container .price-package-one .price-value p,
.price-container .price-package-two .price-value p,
.price-container .price-package-three .price-value p {
font-size: 15px;
font-weight: bold;
}
.price-container .price-package-one .price-value span,
.price-container .price-package-two .price-value span,
.price-container .price-package-three .price-value span{
font-size: 11px;
}
.price-container .price-package-one .price-saving p,
.price-container .price-package-two .price-saving p,
.price-container .price-package-three .price-saving p{
color: red;
font-weight: bold;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<table>
<tbody>
<tr>
<td>Name</td>
<td>Details</td>
</tr>
<tr>
<td>Item 1</td>
<td>
<div class="price-container">
<div class="price-package-one">
<div class="price-value text-left mr-5">
<p class="m-0">$2.49/month</p>
<span>(24 months)</span>
</div>
<div class="price-saving text-left">
<p class="m-0">Save <br>74%</p>
</div>
</div>
<div class="price-package-two">
<div class="price-value text-left mr-5">
<p class="m-0">$6.49/month</p>
<span>(06 months)</span>
</div>
<div class="price-saving text-left">
<p class="m-0">Save <br>47%</p>
</div>
</div>
<div class="price-package-three">
<div class="price-value text-left mr-5">
<p class="m-0">$12.95/month</p>
<span>(01 month)</span>
</div>
<div class="price-saving text-left">
<p class="m-0">Save <br>7%</p>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>

Use a space-between alignment then add spaces on the sides. You can rely on bootstrap classes for this
table {
border-collapse: collapse;
}
table tr {
text-align: center;
margin-bottom: 1px;
}
table td {
border: 1px solid #ddd;
font-size: 13px;
padding: 10px 0;
height: 90px;
width: 100px;
}
table tr td:last-child{
width: 200px;
}
.price-container .price-value p {
font-size: 15px;
}
.price-container .price-value span{
font-size: 11px;
}
.price-container .price-saving p{
color: red;
}
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" rel="stylesheet"/>
<table>
<tbody>
<tr>
<td>Name</td>
<td>Details</td>
</tr>
<tr>
<td>Item 1</td>
<td>
<div class="price-container">
<div class="price-package-one d-flex justify-content-between px-3 mb-2">
<div class="price-value text-left">
<p class="font-weight-bold m-0">$2.49/month</p>
<span>(24 months)</span>
</div>
<div class="price-saving text-left">
<p class="font-weight-bold m-0 ">Save <br>74%</p>
</div>
</div>
<div class="price-package-two d-flex justify-content-between px-3 mb-2">
<div class="price-value text-left">
<p class="font-weight-bold m-0">$6.49/month</p>
<span>(06 months)</span>
</div>
<div class="price-saving text-left">
<p class="font-weight-bold m-0">Save <br>47%</p>
</div>
</div>
<div class="price-package-three d-flex justify-content-between px-3 mb-2">
<div class="price-value text-left">
<p class="font-weight-bold m-0">$12.95/month</p>
<span>(01 month)</span>
</div>
<div class="price-saving text-left">
<p class="font-weight-bold m-0">Save <br>7%</p>
</div>
</div>
</div>
</td>
</tr>
</tbody>
</table>

Related

Issue with CSS styling of Image positioning and div height expansion

I am new to HTML and CSS styling. I need to develop an invoice as per format giving by the client. I have created the invoice,but in most of the places I have used Position = Absolute. If I have to show one product, then it works fine. But if there are multiple products, the product's image and text start to overlap each other and the div in which I am showing the product does not expand neither the footer goes down as per div height expansion.
Here is the template that I have created
I need help to place the products in the div without overlapping each other (div height expansion) and the footer should move downwards as per the height expansion of the div.
Deadline is near and I am really stuck on this issue. Your help will be highly appreciated. Thanks
Try something like this. Note: I didn't incorporate the images that seem to be in the background. And the footer is not styled yet.
body {
margin: 0;
padding: 0.44in;
font-style: normal;
font-weight: 400;
font-size: 9pt;
font-family: Roboto;
color: #333333;
}
.invoice-container {
width: 8.41in;
height: 11.14in;
background-image: url(ci_1.png);
display: flex;
flex-wrap: wrap;
align-items: flex-start;
align-content: flex-start;
justify-content: flex-start;
justify-items: space-around;
}
.invoice-break {
flex-basis: 100%;
}
.invoice-head {
justify-content: center;
line-height: 0.21in;
flex-basis: 100%;
display: flex;
}
.invoice-logo {
width: 0;
margin-left: .15in;
}
.invoice-title {
margin: 0 auto;
font-size: 12pt;
font-weight: 700;
color: #3c3c3c;
}
.invoice-title > div {
font-size: 9pt;
font-weight: 400;
}
.invoice-billing {
line-height: 0.18in;
flex-basis: 100%;
display: flex;
justify-items: flex-start;
margin: .3in .15in 0;
color: #000000;
}
.invoice-billing > * {
flex-grow: 1;
}
.invoice-bill-to {
font-weight: 700;
flex-basis: 2.69in;
}
.invoice-ship-to {
font-weight: 700;
flex-basis: 2.69in;
}
.invoice-detail {
flex-basis: 2.69in;
}
.invoice-order {
flex-basis: 100%;
box-sizing: border-box;
margin: 0.3in 0.15in 0;
}
.invoice-order table {
width: 100%;
}
.invoice-order th {
/* color: #ffffff; */
padding: 0.1in;
}
.invoice-order th.item-desc {
text-align: left;
}
.invoice-order th.item-qty, .invoice-order th.item-price, .invoice-order th.item-total {
text-align: right;
}
.invoice-order td {
vertical-align: center;
padding: 0.1in;
}
.invoice-order td.item-qty, .invoice-order td.item-price, .invoice-order td.item-total {
text-align: right;
}
.product {
display: flex;
}
.product-picture {
margin-right: 0.15in;
}
.product-description {
display: flex;
flex-direction: column;
justify-content: center;
}
.product-title {
font-weight: 700;
}
.invoice-notes {
margin: 0 0.15in;
padding-top: 0.075in;
}
.invoice-notes-title {
font-weight: 700;
}
.invoice-notes-copy {
margin-top: 0.15in;
}
.invoice-shipping-total {
margin-left: auto;
flex-basis: 3in;
margin-right: .15in;
}
.invoice-shipping-total table {
width: 100%;
}
.invoice-shipping-total tr:last-child {
/* color: #ffffff;*/
}
.invoice-shipping-total th {
text-align: left;
padding: .1in;
}
.invoice-shipping-total td {
text-align: right;
padding: .1in;
}
.invoice-footer {
flex-basis: 100%;
display: flex;
justify-content: center;
flex-wrap: wrap;
}
<link href="https://fonts.googleapis.com/css?family=Roboto:400,700&display=swap" rel="stylesheet">
<div class="invoice-container">
<div class="invoice-head">
<div class="invoice-logo"><img width="175" height="53" src="ri_1.png"></div>
<div class="invoice-title">
A4Tech Pakistan
<div>
Online Store - Pakistan<br>
www.a4tech.pk<br>
03 111 611 711
</div>
</div>
</div>
<div class="invoice-break"></div>
<div class="invoice-billing">
<div class="invoice-bill-to">
Bill to<br />
Kashif Ali<br />
Alkhidmat Foundation Pakistan<br />
3 km Khayaban e jinnah near Dream Villas<br />
Society Lahore<br />
Lahore<br />
54000<br />
Tel. +92 323 8479146
</div>
<div class="invoice-ship-to">
Ship to<br />
Kashif Ali<br />
Alkhidmat Foundation Pakistan<br />
3 km Khayaban e jinnah near Dream Villas<br />
Society Lahore<br />
Lahore<br />
54000<br />
Tel. +92 323 8479146
</div>
<div class="invoice-detail">
Invoice No. #1280<br>
<br>
Order Date 03 May, 2019<br>
Payment Cash on delivery (cod)<br>
Shipping
</div>
</div>
<div class="invoice-break"></div>
<div class="invoice-order">
<table>
<thead>
<tr>
<th class="item-desc">Item Description</th>
<th class="item-qty">Qty</th>
<th class="item-price">Price</th>
<th class="item-total">Total</th>
</tr>
</thead>
<tbody>
<tr>
<td class="item-desc">
<div class="product">
<div class="product-picture"><img src="ri_1.png" width="122" height="105" /></div>
<div class="product-description">
<div class="product-title">H151 Stereo Headset - 1 Year Warranty</div>
<div class="product-item-number">981-000587</div>
</div>
</div>
</td>
<td class="item-qty">× 1</td>
<td class="item-price">Rs.2,399.00 </td>
<td class="item-total">Rs.2,399.00 </td>
</tr>
</tbody>
</table>
</div>
<div class="invoice-break"></div>
<div class="invoice-notes">
<div class="invoice-notes-title">Notes</div>
<div class="invoice-notes-copy">
THIS INVOICE AND PACKING MATERIAL IS MANDATORY FOR<br>
WARRANTY PURPOSE.
</div>
<div class="invoice-notes-serial">SERIAL # 1845ALA89609</div>
</div>
<div class="invoice-shipping-total">
<table>
<tr>
<th>Subtotal</th>
<td>Rs.2,399.00</td>
</tr>
<tr>
<th>Shipping</th>
<td>Rs.0.00</td>
</tr>
<tr>
<th>Total</th>
<td>Rs.2,399.00</td>
</tr>
</table>
</div>
<div class="invoice-break"></div>
<div class="invoice-footer">
<img style="width:0.23in;height:0.23in" src="ri_5.png" />
<img style="width:0.23in;height:0.23in" src="ri_6.png" />
<img style="width:0.23in;height:0.23in" src="ri_7.png" />
<div class="invoice-break"></div>
www.logitech.pk
<div class="invoice-break"></div>
<p>If you have any questions, please do get in contact.</p>
<div class="invoice-break"></div>
info#logitech.pk
<div class="invoice-break"></div>
<p>Thanks for your business!</p>
</div>
</div>
Use some css framework is faster and more convenient. Below is an example for such a quick example -> look bootstrap documentation
.container {
font-size: 12px;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css">
<div class="container mt-5">
<div class="row">
<div class="col-4"><img src="https://fakeimg.pl/250x100/"></div>
<div class="col-8">
<ul class="list-unstyled">
<li><strong>A4Tech Pakistan</strong></li>
<li>Online Store - Pakistan</li>
<li>www.a4tech.pk</li>
<li>03 111 611 711</li>
</ul>
</div>
</div>
<div class="row my-5">
<div class="col-4">
<b>
Bill to<br>
Kashif Ali<br>
Alkhidmat Foundation Pakistan<br>
3 km Khayaban e jinnah near Dream Villas<br>
Society Lahore<br>
Lahore<br>
54000<br>
Tel. +92 323 8479146
</b>
</div>
<div class="col-4">
<b>
Ship to<br>
Kashif Ali<br>
Alkhidmat Foundation Pakistan<br>
3 km Khayaban e jinnah near Dream Villas<br>
Society Lahore<br>
Lahore<br>
54000<br>
Tel. +92 323 8479146<br>
</b>
</div>
<div class="col-4">
<b>Invoice No. #1280 Order Date 03 May, 2019 </b><br>
Payment Cash on delivery (cod) <br>
Shipping
</div>
</div>
<div class="row mb-3">
<div class="col-2"><img src="https://fakeimg.pl/130/"></div>
<div class="col-5">H151 Stereo Headset - 1 Year Warranty <br>981-000587</div>
<div class="col-1">x1</div>
<div class="col-2">Rs.2,399.00</div>
<div class="col-2">Rs.2,399.00</div>
</div>
<div class="row mb-3">
<div class="col-2"><img src="https://fakeimg.pl/130/"></div>
<div class="col-5">H151 Stereo Headset - 1 Year Warranty <br>981-000587</div>
<div class="col-1">x1</div>
<div class="col-2">Rs.2,399.00</div>
<div class="col-2">Rs.2,399.00</div>
</div>
<div class="row mb-3">
<div class="col-2"><img src="https://fakeimg.pl/130/"></div>
<div class="col-5">H151 Stereo Headset - 1 Year Warranty <br>981-000587</div>
<div class="col-1">x1</div>
<div class="col-2">Rs.2,399.00</div>
<div class="col-2">Rs.2,399.00</div>
</div>
<div class="row notes">
<div class="col-7">
<p><b>Notes</b></p>
<p>THIS INVOICE AND PACKING MATERIAL IS MANDATORY FOR <br>
WARRANTY PURPOSE. <br>
SERIAL # 1845ALA89609 </p>
</div>
<div class="col-5">
<div class="row">
<div class="col-5">Subtotal</div>
<div class="col-5 text-right">Rs.2,399.00</div>
</div>
<div class="row">
<div class="col-5">Shipping</div>
<div class="col-5 text-right">Rs.0.00</div>
</div>
</div>
</div>
<div class="row justify-content-md-center my-5">
<div class="col-6">
<div class="row justify-content-md-center">
<div class="col-2"><img src="https://fakeimg.pl/50/"></div>
<div class="col-2"><img src="https://fakeimg.pl/50/"></div>
<div class="col-2"><img src="https://fakeimg.pl/50/"></div>
</div>
</div>
</div>
<div class="row justify-content-md-center info text-center">
<p>www.logitech.pk<br>
If you have any questions, please do get in contact. <br>
info#logitech.pk <br>
<b>Thanks for your business!</b><br>
</p>
</div>
</div>

Bootstrap4 - Splitting the Row into two columns

I need to split a row into two so that I can accommodate two headings in a row, something like below:
With the current code that I have written, I am unable to separate the row into two like the above and also unable to maintain the responsiveness like below:
Below is the output that I am getting with the current code:
Below here is the code:
<div class="container-fluid mail-body" style="width: 740px;">
<div id="account" class="row your-account">
<div class="col text-right" style="line-height: 20px; height: 20px; color:#004990; text-decoration:none; font-family:Helvetica, Arial, sans-serif; font-size:10px;">
Your Account
</div>
</div>
<!-- /.your-account -->
<div id="logo" class="row">
<div class="col text-center" style="background-color:#0471AF; height:100px; display: flex; justify-content: center;">
LOGO
</div>
</div>
<!-- /.logo -->
<div id="order-text" class="row">
<div class="col text-center" style="min-height: 98px; vertical-align:middle; font-family:Helvetica, Arial, sans-serif; font-size:36px; color: #0471AF; font-weight:100; display: flex; justify-content: center;">
<span style="align-self: center;">Heading Text</span>
</div>
</div>
<!-- /.order-text -->
<div class="row">
<div id="left-side-text" class="col-md-8 col-sm-12" style=" line-height: 18px;">
<span style="vertical-align:top; font-family:Helvetica, Arial, sans-serif; font-size:14px; color: #333333; text-decoration: none; text-align: left; line-height: 18px; font-weight:100;">
Dear XYZ,
</span>
<br>
<br>
<span style="font-family:Helvetica, Arial, sans-serif; font-size:17px; text-decoration: none; text-align:left; padding-bottom:20px;">Good news! Your order is confirmed.</span>
<br>
<br>
<span style="vertical-align:top; font-family:Helvetica, Arial, sans-serif; font-size:14px; color: #333333; text-decoration: none; text-align: left; font-weight:100;">
Some other text
</span>
</div>
<!-- /.left-side text -->
<div id="order-information" class="col-md-4 col-sm-12 order-2">
<div class="col" style="height: 43px; vertical-align:middle; font-family:Helvetica, Arial, sans-serif; font-size:16px; color: #333333; text-decoration: none; font-weight:700; background: #f2f2f2; padding: 10px; border: 1px solid #999999; border-bottom: none;">
Order Details
</div>
<div class="col" style="font-family:Helvetica, Arial, sans-serif; font-size:12px; color: #333333; padding: 10px; height: 73px; border: 1px solid #999999; border-top: none;">
<table>
<tr>
<td class="col-2 font-weight-bold" style="padding-bottom: 10px; padding-left: 0">Order Date:</td>
<td class="col-2" style="padding-bottom: 10px; padding-left: 0">03/06/2016</td>
</tr>
<tr>
<td class="col-2 font-weight-bold" style="padding: 0px;">Order #:</td>
<td class="col-2" style="padding-bottom: 10px; padding-left: 0">123456789</td>
</tr>
</table>
</div>
</div>
<!-- /.order-information -->
<div class="col-md-11 col-sm-12" style="line-height: 18px; vertical-align:top; font-family:Helvetica, Arial, sans-serif; font-size:14px; color: #333333; text-decoration: none; text-align: left; font-weight:100;">
<br>
<br>Text1
<br>
<br> Text
<br> Text
</div>
</div>
<div id="confirmation-email" class="row order-1">
<div class="col-md-11 col-sm-12" style="line-height: 18px; vertical-align:top; font-family:Helvetica, Arial, sans-serif; font-size:14px; color: #333333; text-decoration: none; text-align: left; font-weight:100;">
<br>
<br>Text1
<br>
<br> Text
<br> Text
</div>
</div>
<div class="row">
<div class="col-md-12" >
<div class="col" style="height: 36px; vertical-align:middle; font-size: 12px; font-family:Helvetica, Arial, sans-serif; color: #333333; text-decoration: none; font-weight:700; background: #f2f2f2; padding: 10px; border: 1px solid #999999; border-bottom: none;">
<span class="">Product(s) Ready for Pickup</span>
<span class="text-right">Quantity</span>
</div>
</div>
</div>
Please help me with the proper setup of the html as well the bootstrap classes so as to achieve the expected result.
Thanks!
Here is super easy/clean code:
<div class="row">
<div class="col" >
Product(s) Ready for Pickup
</div>
<div class="col text-right" >
Quantity
</div>
</div>
See the preview link: https://codepen.io/ziruhel/pen/LOZjWZ
You need to make two columns within your row using the col-sm-6 (or relevant classes as per the device needs). Assuming you need the row to have 2 columns for small, Medium, Large devices and 1 column for extra small devices, Below is my suggestion (Note: I have removed the style rules for better readability).
<div class="row col-md-12">
<div class="col-xs-12 col-sm-6" >
<span class="float-left">Product(s) Ready for Pickup</span>
</div>
<div class="col-xs-12 col-sm-6" >
<span class="float-right">Quantity</span>
</div>
</div>
Use col-xl-{value} to get columns.
Bootstrap Grid http://getbootstrap.com/docs/4.0/layout/grid/
<div class="row"> //row
<div class="col-xs-6" > //column 1 for extra large screen, use sm for small, md for medium screen
<span>Product(s) Ready for Pickup</span>
</div>
<div class="col-xs-6" > //column 2
<span>Quantity</span>
</div>
</div>
You can use col-md-* class for child element inside the parent row class to split the columns for your need.
<div class="row">
<div class="col-md-9" >
Product(s) Ready for Pickup
</div>
<div class="col-md-3 text-center" >
Quantity
</div>
</div>

Div-(Table)Layout breaks when surrounded by link

I have a problem and I tried so many hours to solve this, so I wanted to ask you if you have an idea for me.
I made a Div-Table-Layout and everything ist ok now.
Now I want to make a whole row clickable with just css Style and tried the following in the first row:
<a><tr><td></td></tr></a>
When I do this, the columns aren't as wide as before I entered the a-tag.
Is there any way to do this?
<div class="divTable">
<div class="divTableBody">
<a href="#" class="divTableRow">
<div class="col-xs-2 divTableCell">21</div>
<div class="divTableCell divTableCellRight col-xs-10">Test</div>
</a>
<div class="divTableRow">
<div class="col-xs-2 divTableCell ">21</div>
<div class="divTableCell divTableCellRight col-xs-10">Test</div>
</div>
<div class="divTableRow">
<div class="col-xs-2 divTableCell ">21</div>
<div class="divTableCell divTableCellRight col-xs-10">Test</div>
</div>
</div>
</div>
https://jsfiddle.net/9b905xry/2/
Just remove the div tag and add divTableRow to anchortag...
Hope this will help you..
.divTable {
display: table;
width: calc(100% - 30px);
margin: 15px;
}
.divTableRow {
display: table-row;
}
.divTableRow:nth-of-type(odd) {
background: #e0e0e0;
}
.divTableRow:nth-of-type(even) {
background: #FFFFFF;
}
.divTableHeading {
background-color: #EEE;
display: table-header-group;
}
.divTableCell,
.divTableHead {
height: 96px;
display: table-cell;
padding: 1em;
text-align: center;
vertical-align: middle;
float: none;
}
.divTableCellLeft {
text-align: center;
}
.divTableCellRight {
text-align: left;
}
.divTableHeading {
background-color: #EEE;
display: table-header-group;
font-weight: bold;
}
.divTableFoot {
background-color: #EEE;
display: table-footer-group;
font-weight: bold;
}
.divTableBody {
display: table-row-group;
}
<div class="divTable">
<div class="divTableBody">
<a href="" class="divTableRow">
<div class="col-xs-2 divTableCell">21</div>
<div class="divTableCell divTableCellRight col-xs-10">Test</div>
</a>
<div class="divTableRow">
<div class="col-xs-2 divTableCell ">21</div>
<div class="divTableCell divTableCellRight col-xs-10">Test</div>
</div>
<div class="divTableRow">
<div class="col-xs-2 divTableCell ">21</div>
<div class="divTableCell divTableCellRight col-xs-10">Test</div>
</div>
</div>
</div>
I think you might be going about this the wrong way I'm afraid. I really think you need to just make an html table (since this looks very much like tabular data) and simply have links in the table cells.
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<table class="table">
<tr>
<td>21</td>
<td>Test</td>
</tr>
<tr>
<td>21</td>
<td>Test</td>
</tr>
</table>

Creating complex table using CSS

I want to create something like this using divs and it also should be without using display:table css rule etc. How do I create table header this??
May be try this as a starting point? You might need to tweak it a lot.
* {box-sizing: border-box;}
.row {overflow: hidden; clear: both;}
.cell {border: 1px solid #999; padding: 0px; float: left;}
.cell.full {float: none;}
.col-1 {width: 20%;}
.col-2 {width: 40%;}
.col-3 {width: 60%;}
.col-33 {width: 33.3%;}
.row-2 {height: 3em;}
<div class="row">
<div class="cell col-1 row-2">Subject</div>
<div class="cell col-3 row-2">
<div class="row">
<div class="cell full">First Term</div>
</div>
<div class="row">
<div class="cell col-33">October Test</div>
<div class="cell col-33">December Exam</div>
<div class="cell col-33">Term Average</div>
</div>
</div>
<div class="col-1 row-2 cell">Teacher's Evaluation</div>
</div>
Preview:
If you can use flexbox can i use flexbox
The benefit of using flexbox is that you can get the the same result as you using the table tag including vertical-align:middle.
In the snippet, keep attention to the text-alignment in the cells.
You can use flexboxgrid like this:
[class*="col"] {
text-align:center;
border:1px solid;
display: flex;
justify-content: center;
flex-direction: column;
}
<link href="http://cdn.jsdelivr.net/flexboxgrid/6.3.0/flexboxgrid.min.css" rel="stylesheet" />
<div class="row ">
<div class="col-xs-3">Subject</div>
<div class="col-xs-6">
<div class="row">
<div class="col-xs-12">First Term</div>
</div>
<div class="row">
<div class="col-xs-4">October Test</div>
<div class="col-xs-4">December Exam</div>
<div class="col-xs-4">Term Average</div>
</div>
</div>
<div class="col-xs-3">Teacher's Evaluation</div>
</div>
The result:
http://jsbin.com/zetaro/edit?html,css,output
Just use colspan and rowspan =)
tutorial how to do it
I made it:
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
<table>
<tr>
<th rowspan="2"><br>Subject<br></th>
<th colspan="3">First term</th>
<th rowspan="2">Teacher's Evaluation</th>
</tr>
<tr>
<td>October test</td>
<td>December exam</td>
<td>Term Average</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</table>
https://jsfiddle.net/b3aqLny1/
Try this
.table {
width: 100%;
table-layout: fixed;
display: table;
text-align: center;
}
.table .row{
display: table-row;
}
.table .row .col {
display: table-cell;
vertical-align: middle;
height: 100px;
border: 2px solid #333;
width: 33%;
}
.table .col.col-big {
width: 50%;
}
span {
display: inline-block;
padding: 10px;
}
.inner-table.table .row .col {border-width: 1px;}
<div class="table">
<div class="row">
<div class="col">
<span>Subject</span>
</div>
<div class="col col-big">
<div class="table inner-table">
<div class="row">
<div class="col one-col" style="width: 100%">
<span>First Term</span>
</div>
</div>
<div class="row">
<div class="table inner-table">
<div class="row">
<div class="col"><span>Test 1</span></div>
<div class="col"><span>Test 2</span></div>
<div class="col"><span>Test 3</span></div>
</div>
</div>
</div>
</div>
</div>
<div class="col">
<span>Teacher's Evaluation</span>
</div>
</div>
</div>

HTML Table: Having a border on just the table header with border-collapse:separate on the table

This is how I need my table to look:
I need to add a solid border beneath the table heading row. However, I also need to have spacing between the cells of the table. I have to use the border-collapse property on the table in order to get spacing between the gray cells, and "border-collapse: separate" prevents me from adding a bottom border to the heading row.
How can I add a solid border beneath the table header while also maintaining the spacing between the table columns?
These are the styles I have; the border-collapse style negates the border-bottom. When I remove the border-collapse, the border-bottom works.
tr.heading{
border-bottom: 1px solid black;
}
table{
border-collapse: separate;
}
Here's a fiddle:
https://jsfiddle.net/8u9krzyg/
This answer utilizes border:collapse; plus margin and border on your <div class="wrap"> element that you have in your table cells to provide the pseudo cell borders.
EDITED: I posted another method using ::after on the th elements to span the spacing. It has better browser support.
th {
text-align:left;
}
body.checkout-cart-2 { }
.checkout-cart-2 #cart-table{
width:100%;
}
.cart-status li {
display: inline;
}
.checkout-cart-2 .return-link {
margin:1.5em 0;
}
.checkout-cart-2 .cart-left {
margin-bottom:1.5em;
padding:15px;
}
.checkout-cart-2 .cart-left, .checkout-cart-2 .cart-right{
background:white;
}
#cart-table {
border-collapse: collapse; /* changed from separate */
border:none;
}
#cart-table th {
font-family: "Verdana";
font-size: 12px;
padding: 4px 10px;
text-transform: uppercase;
}
.cart-row {
font-family: "Verdana";
height: 100%; /* needed for full height .wrap */
}
.cart-row td {
vertical-align: top;
background: white;
padding: 0;
height: 100%;
}
.cart-row .description{
padding:0;
}
.cart-row .item-thumb{
padding-left:0;
}
.cart-row .item-name a {
font-size: 16px;
color: #0070c0;
font-weight: bold;
}
.cart-row .item-num {
font-size: 12px;
}
.cart-row .update a{
color: #0070c0;
}
.cart-row div.remove a.btn{
color: #0070c0;
background:none;
font-size:22px !important;
padding: 0 5px 0 1px;
}
.heading { /* new style */
border-bottom: 1px solid black;
}
.gray .wrap { /* new style - moved background color from td to .wrap */
background: #f6f6f6 none repeat scroll 0 0;
}
.wrap { /*new style to create pseudo cell borders */
height: 100%;
padding: 0 10px;
display: inline-block;
width: 100%; /* fall back for browsers that do not support calc()*/
width: calc(100% - 24px); /* calculates 100% width - 20 px padding + 4px right margin*/
border-bottom: 4px solid #f2f2f2;
margin-right: 4px; /* creates white space "pseudo/implied" border between cells */
}
.wrap > *:first-child {
padding-top: 10px;
}
.wrap > *:last-child {
padding-bottom: 10px;
}
.cart-row td:last-child .wrap, .remove .wrap {
margin-right: 0; /* removes "pseudo/implied" border on last cell .wrap */
width: calc(100% - 20px); /* Calculates 100% width - 20 px padding */
}
.availability>span {
font-weight: normal;
}
/* Clearfix */
.checkout-cart-2 .cart-left:before,
.checkout-cart-2 .cart-left:after {
content: " ";
display: table;}
.checkout-cart-2 .cart-left:after {
clear: both;}
.checkout-cart-2 ul.cart-items {
margin:0;
list-style:none;
}
#media all and (min-width: 769px) {
.checkout-cart-2 .cart-left {
float:left;
width:75%;
}
}
.checkout-cart-2 .cart-right {
margin-bottom:1.5em;
}
.checkout-cart-2 .cart-left .btns {
margin:1.5em 0;
}
.checkout-cart-2 .cart-left .btns .btn {
width:100%;
margin-bottom:1em;
}
.checkout-cart-2 .cart-right .btns a.btn {
width:100%;
margin-bottom:1em;
}
#media all and (min-width: 769px) {
.checkout-cart-2 .cart-right {
float:right;
width:25%;
}
}
.checkout-cart-2 .item-details .item-name {
padding-right:2.5em;
}
#media all and (min-width: 769px) {
.checkout-cart-2 .item-list .item-details {
padding-right:1em !important;
}
.checkout-cart-2 .item-details .item-name {
padding-right:3.5em;
}
.checkout-cart-2 .item-opt .item-subtotal {
float:right;
clear: right;
}
}
.checkout-cart-2 .item-list .actions-panel .item-actions {
text-align:left; }
.checkout-cart-2 .item-list .item-code-notes {
padding:0;
float:left;
width:100%;
}
.checkout-cart-2 .item-list .item-actions-wrap {
padding-left:0;
padding-right:0;
padding-bottom:0;
float:left;
width:100%;
}
.checkout-cart-2 .quote-items-note {
background:#fff6c5;
border-color:#ffd800;
}
<div id="cartgrid">
<table id="cart-table">
<tbody><tr class="heading">
<th>Product Information</th>
<th>Quantity</th>
<th>Item Price</th>
<th>Subtotal</th>
<th></th>
</tr>
<tr class="cart-row gray" data-orderlineid="02e9151d-24b4-46ca-8e9f-a4d000adbd83">
<td class="product-info" width="45%">
<div class="wrap">
<div class="small-4 columns item-thumb"><img src="" alt="95T Achieve Treadmill"></div>
<div class="small-8 columns description">
<div class="item-name">
<a href="">
95T Achieve Treadmill
</a>
</div>
<div class="item-num">
<span class="item-num-sku">Product Code: 456009801</span>
</div>
<div class="availability">
<span class="instock">In Stock</span>
</div>
</div>
</div>
</td>
<td class="quantity">
<div class="wrap">
<div class="item-qty">
<input type="text" id="02e9151d-24b4-46ca-8e9f-a4d000adbd83_qty" data-qty-input="" value="3" class="numerictextbox qty txt">
</div>
<div class="update">
<a class="update-btn" id="02e9151d-24b4-46ca-8e9f-a4d000adbd83_update" onclick="">Update</a>
</div>
</div>
</td>
<td class="price">
<div class="wrap">
<div class="price">
<span class="price">$3,599.00</span>
</div>
</div>
</td>
<td class="subtotal">
<div class="wrap">
<div class="price">
<div class="item-subtotal">
$10,797.00 </div>
</div>
</div>
</td>
<td class="remove">
<div class="wrap">
<div class="remove">
<a class="btn btn-remove" onclick="">
<i class="fa fa-times"></i>
</a>
</div>
</div>
</td>
</tr>
<tr class="cart-row" data-orderlineid="01a6aefa-7bb7-4559-b4db-a4d000c95fc8">
<td class="product-info" width="45%">
<div class="wrap">
<div class="small-4 columns item-thumb"><img src="" alt="Biceps Curl"></div>
<div class="small-8 columns description">
<div class="item-name">
<a href="">
Biceps Curl
</a>
</div>
<div class="item-num">
<span class="item-num-sku">Product Code: 455009813</span>
</div>
<div class="availability">
<span class="instock">In Stock</span>
</div>
</div>
</div>
</td>
<td class="quantity">
<div class="wrap">
<div class="item-qty">
<input type="text" id="01a6aefa-7bb7-4559-b4db-a4d000c95fc8_qty" data-qty-input="" value="1" class="numerictextbox qty txt">
</div>
<div class="update">
<a class="update-btn" id="01a6aefa-7bb7-4559-b4db-a4d000c95fc8_update" onclick="">Update</a>
</div>
</div>
</td>
<td class="price">
<div class="wrap">
<div class="price">
<span class="price">$149.99</span>
</div>
</div>
</td>
<td class="subtotal">
<div class="wrap">
<div class="price">
<div class="item-subtotal">
$149.99 </div>
</div>
</div>
</td>
<td class="remove">
<div class="wrap">
<div class="remove">
<a class="btn btn-remove" onclick="">
<i class="fa fa-times"></i>
</a>
</div>
</div>
</td>
</tr>
<tr class="cart-row gray" data-orderlineid="2d0c2838-645a-4849-9600-a4d000c9627a">
<td class="product-info" width="45%">
<div class="wrap">
<div class="small-4 columns item-thumb"><img src="" alt="XI8 CYCLEPRO Exercise Bike"></div>
<div class="small-8 columns description">
<div class="item-name">
<a href="">
XI8 CYCLEPRO Exercise Bike
</a>
</div>
<div class="item-num">
<span class="item-num-sku">Product Code: LFR3995</span>
</div>
<div class="availability">
<span class="instock">In Stock</span>
</div>
</div>
</div>
</td>
<td class="quantity">
<div class="wrap">
<div class="item-qty">
<input type="text" id="2d0c2838-645a-4849-9600-a4d000c9627a_qty" data-qty-input="" value="1" class="numerictextbox qty txt">
</div>
<div class="update">
<a class="update-btn" id="2d0c2838-645a-4849-9600-a4d000c9627a_update" onclick="">Update</a>
</div>
</div>
</td>
<td class="price">
<div class="wrap">
<div class="price">
<span class="price-sale">$1,999.99</span>
<span class="price-old">$2,199.00</span>
</div>
</div>
</td>
<td class="subtotal">
<div class="wrap">
<div class="price">
<div class="item-subtotal">
$1,999.99 </div>
</div>
</div>
</td>
<td class="remove">
<div class="wrap">
<div class="remove">
<a class="btn btn-remove" onclick="">
<i class="fa fa-times"></i>
</a>
</div>
</div>
</td>
</tr>
</tbody></table>
</div>
Another Method
Here is another method that uses th::after to create the border underneath the table headers. This method has better cross browser support.
th {
text-align:left;
}
body.checkout-cart-2 { }
.checkout-cart-2 #cart-table{
width:100%;
}
.cart-status li {
display: inline;
}
.checkout-cart-2 .return-link {
margin:1.5em 0;
}
.checkout-cart-2 .cart-left {
margin-bottom:1.5em;
padding:15px;
}
.checkout-cart-2 .cart-left, .checkout-cart-2 .cart-right{
background:white;
}
#cart-table {
border-collapse: separate:
border:none;
}
#cart-table th {
font-family: "Verdana";
font-size: 12px;
padding: 4px 10px;
text-transform: uppercase;
position: relative;
border-bottom: solid 2px black; /* base/fallback border for older browsers */
}
.cart-row {
font-family: "Verdana";
height: 100%; /* needed for full height .wrap */
}
.cart-row td {
vertical-align: top;
background: white;
padding: 10px;
height: 100%;
}
.cart-row .description{
padding:0;
}
.cart-row .item-thumb{
padding-left:0;
}
.cart-row .item-name a {
font-size: 16px;
color: #0070c0;
font-weight: bold;
}
.cart-row .item-num {
font-size: 12px;
}
.cart-row .update a{
color: #0070c0;
}
.cart-row div.remove a.btn{
color: #0070c0;
background:none;
font-size:22px !important;
padding: 0 5px 0 1px;
}
.heading {
position: relative;
}
#cart-table th::after { /* creates a pseudo border to span gap in th spacing */
background: black none repeat scroll 0 0;
bottom: -2px;
content: "";
display: block;
height: 2px; /* matches #cart-table th border-bottom value */
left: 0px;
position: absolute;
right: -2px; /* Matches table border-spacing value */
}
#cart-table th:last-child::after {
right: 0px; /* Reset pseudo border so it does not extend outside of table */
}
.gray td { /* new style - moved background color from td to .wrap */
background: #f6f6f6 none repeat scroll 0 0;
}
.availability>span {
font-weight: normal;
}
/* Clearfix */
.checkout-cart-2 .cart-left:before,
.checkout-cart-2 .cart-left:after {
content: " ";
display: table;}
.checkout-cart-2 .cart-left:after {
clear: both;}
.checkout-cart-2 ul.cart-items {
margin:0;
list-style:none;
}
#media all and (min-width: 769px) {
.checkout-cart-2 .cart-left {
float:left;
width:75%;
}
}
.checkout-cart-2 .cart-right {
margin-bottom:1.5em;
}
.checkout-cart-2 .cart-left .btns {
margin:1.5em 0;
}
.checkout-cart-2 .cart-left .btns .btn {
width:100%;
margin-bottom:1em;
}
.checkout-cart-2 .cart-right .btns a.btn {
width:100%;
margin-bottom:1em;
}
#media all and (min-width: 769px) {
.checkout-cart-2 .cart-right {
float:right;
width:25%;
}
}
.checkout-cart-2 .item-details .item-name {
padding-right:2.5em;
}
#media all and (min-width: 769px) {
.checkout-cart-2 .item-list .item-details {
padding-right:1em !important;
}
.checkout-cart-2 .item-details .item-name {
padding-right:3.5em;
}
.checkout-cart-2 .item-opt .item-subtotal {
float:right;
clear: right;
}
}
.checkout-cart-2 .item-list .actions-panel .item-actions {
text-align:left; }
.checkout-cart-2 .item-list .item-code-notes {
padding:0;
float:left;
width:100%;
}
.checkout-cart-2 .item-list .item-actions-wrap {
padding-left:0;
padding-right:0;
padding-bottom:0;
float:left;
width:100%;
}
.checkout-cart-2 .quote-items-note {
background:#fff6c5;
border-color:#ffd800;
}
<div id="cartgrid">
<table id="cart-table">
<tbody><tr class="heading">
<th>Product Information</th>
<th>Quantity</th>
<th>Item Price</th>
<th>Subtotal</th>
<th></th>
</tr>
<tr class="cart-row gray" data-orderlineid="02e9151d-24b4-46ca-8e9f-a4d000adbd83">
<td class="product-info" width="45%">
<div class="wrap">
<div class="small-4 columns item-thumb"><img src="" alt="95T Achieve Treadmill"></div>
<div class="small-8 columns description">
<div class="item-name">
<a href="">
95T Achieve Treadmill
</a>
</div>
<div class="item-num">
<span class="item-num-sku">Product Code: 456009801</span>
</div>
<div class="availability">
<span class="instock">In Stock</span>
</div>
</div>
</div>
</td>
<td class="quantity">
<div class="wrap">
<div class="item-qty">
<input type="text" id="02e9151d-24b4-46ca-8e9f-a4d000adbd83_qty" data-qty-input="" value="3" class="numerictextbox qty txt">
</div>
<div class="update">
<a class="update-btn" id="02e9151d-24b4-46ca-8e9f-a4d000adbd83_update" onclick="">Update</a>
</div>
</div>
</td>
<td class="price">
<div class="wrap">
<div class="price">
<span class="price">$3,599.00</span>
</div>
</div>
</td>
<td class="subtotal">
<div class="wrap">
<div class="price">
<div class="item-subtotal">
$10,797.00 </div>
</div>
</div>
</td>
<td class="remove">
<div class="wrap">
<div class="remove">
<a class="btn btn-remove" onclick="">
<i class="fa fa-times"></i>
</a>
</div>
</div>
</td>
</tr>
<tr class="cart-row" data-orderlineid="01a6aefa-7bb7-4559-b4db-a4d000c95fc8">
<td class="product-info" width="45%">
<div class="wrap">
<div class="small-4 columns item-thumb"><img src="" alt="Biceps Curl"></div>
<div class="small-8 columns description">
<div class="item-name">
<a href="">
Biceps Curl
</a>
</div>
<div class="item-num">
<span class="item-num-sku">Product Code: 455009813</span>
</div>
<div class="availability">
<span class="instock">In Stock</span>
</div>
</div>
</div>
</td>
<td class="quantity">
<div class="wrap">
<div class="item-qty">
<input type="text" id="01a6aefa-7bb7-4559-b4db-a4d000c95fc8_qty" data-qty-input="" value="1" class="numerictextbox qty txt">
</div>
<div class="update">
<a class="update-btn" id="01a6aefa-7bb7-4559-b4db-a4d000c95fc8_update" onclick="">Update</a>
</div>
</div>
</td>
<td class="price">
<div class="wrap">
<div class="price">
<span class="price">$149.99</span>
</div>
</div>
</td>
<td class="subtotal">
<div class="wrap">
<div class="price">
<div class="item-subtotal">
$149.99 </div>
</div>
</div>
</td>
<td class="remove">
<div class="wrap">
<div class="remove">
<a class="btn btn-remove" onclick="">
<i class="fa fa-times"></i>
</a>
</div>
</div>
</td>
</tr>
<tr class="cart-row gray" data-orderlineid="2d0c2838-645a-4849-9600-a4d000c9627a">
<td class="product-info" width="45%">
<div class="wrap">
<div class="small-4 columns item-thumb"><img src="" alt="XI8 CYCLEPRO Exercise Bike"></div>
<div class="small-8 columns description">
<div class="item-name">
<a href="">
XI8 CYCLEPRO Exercise Bike
</a>
</div>
<div class="item-num">
<span class="item-num-sku">Product Code: LFR3995</span>
</div>
<div class="availability">
<span class="instock">In Stock</span>
</div>
</div>
</div>
</td>
<td class="quantity">
<div class="wrap">
<div class="item-qty">
<input type="text" id="2d0c2838-645a-4849-9600-a4d000c9627a_qty" data-qty-input="" value="1" class="numerictextbox qty txt">
</div>
<div class="update">
<a class="update-btn" id="2d0c2838-645a-4849-9600-a4d000c9627a_update" onclick="">Update</a>
</div>
</div>
</td>
<td class="price">
<div class="wrap">
<div class="price">
<span class="price-sale">$1,999.99</span>
<span class="price-old">$2,199.00</span>
</div>
</div>
</td>
<td class="subtotal">
<div class="wrap">
<div class="price">
<div class="item-subtotal">
$1,999.99 </div>
</div>
</div>
</td>
<td class="remove">
<div class="wrap">
<div class="remove">
<a class="btn btn-remove" onclick="">
<i class="fa fa-times"></i>
</a>
</div>
</div>
</td>
</tr>
</tbody></table>
</div>
For some reason I'm not sure you'll like my answer, however add the following after the heading row:
<tr><td style="border-top:1px solid black;" colspan="4"></td></tr>
where 4 is the number of columns. The border line will nicely ignore cell spacing, because it's one cell.