Custom borders in Bootstrap 4 table - css

So I'm building a web shop cart (using Bootstrap 4.1) and I have to make a list of items in the cart with quantity, the price and total-price... I've decided to use a table for this and ran into an following problem:
I'm trying to make a table that has to look like this:
and my best attempt gave me a table that looks like this..:
My question to you fellow internet strangers is how do I make the table borders surounding the "quantity" to look like in the first picture???
and how do I merge the last cells to get the total price (23,97 €) alighned in the middle of the table like in the first picture??
P.S. Is using a table even a corect choice or should I have used a different element like an or ?
Thanks in advance fellow spacemans :)
My Code:
HTML:
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col"> </th>
<th scope="col">Product</th>
<th scope="col">Quantity</th>
<th scope="col">Price</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">#</th>
<td>100 % Mango</td>
<td>1 X</td>
<td>12.99 €</td>
</tr>
<tr>
<th scope="row">#</th>
<td>Vanilla</td>
<td>2 x</td>
<td>10.98 €</td>
</tr>
</tbody>
</table>
</div>
SCSS:
.table {
border-right: 1px solid #000000;
background-color: transparent;
color: #000000;
text-align: center;
thead {
font-family: 'Alegreya', serif;
border: none;
th {
border: none;
}
}
tbody {
font-weight: 700;
text-transform: uppercase;
border: none;
font-size: 1.5rem;
th, td {
border: none;
&:nth-child(3) {
border-right: 2px solid #000000;
border-left: 2px solid #000000;
}
}
}
}

You can achieve that using :after as described below, and using normal border-right for the forth row.
with :after
td{
position:relative; //positioning the td so that the :after would use it for absolute positioning
//for the small borders on 2nd and 3rd columns
&:nth-child(2):after,&:nth-child(3):after{
content:'';
width:2px;
height:20px;
background:#000;
display:block;
position:absolute;
top:50%;
right:0;
transform:translateY(-50%); //moving the element back up by half its height to center it vertically
}
//for the big border on the 4th column
&:nth-child(4){
border-right:2px solid #000; //do that for the th aswell
}
}
Full Code:
.table {
border-right: 1px solid #000000;
background-color: transparent;
color: #000000;
text-align: center;
thead {
font-family: 'Alegreya', serif;
border: none;
th {
border: none;
&:nth-child(4){
border-right:2px solid #000;
}
}
}
tbody {
font-weight: 700;
text-transform: uppercase;
border: none;
font-size: 1.5rem;
td{
position:relative;
&:nth-child(2):after,&:nth-child(3):after{
content:'';
width:2px;
height:20px;
background:#000;
display:block;
position:absolute;
top:50%;
right:0;
transform:translateY(-50%);
}
&:nth-child(4){
border-right:2px solid #000;
}
}
th, td {
border: none;
}
}
}

Here us working one:https://jsfiddle.net/b2f03y1p/17/
Instead this code:
&:nth-child(3) {
border-right: 2px solid #000000;
border-left: 2px solid #000000;
}
Use this code:
td:nth-child(2):after,td:nth-child(3):after{
content: '';
height: 21px;
width: 2px;
background-color: black;
position: absolute;
top: 35%;
left: 90%;
}
td:nth-child(4):after{
content: '';
height: 100%;
width: 2px;
background-color: black;
position: absolute;
left: 90%;
}

Related

Adding some space between tables with css

I have generated a HTML page with several tables.
Right now they show one after another without any space between them
my current css file is very simple
table {
font-family: arial, sans-serif;
border-collapse: collapse;
/*width: 100%;*/
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
How can I add some spacing between the tables using only css?
I tried
table{
margin-right: 10px;
float: left;
}
but it did not work out
I modified it to
margin-bottom:10px;
float:bottom;
and it seems to work.
Your code should work. Check this snippet:
table {
font-family: arial, sans-serif;
border-collapse: collapse;
margin-right:10px;
float:left;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
<table>
<tr><td>aaaaa</td></tr>
</table>
<table>
<tr><td>bbbb</td></tr>
</table>
<table>
<tr><td>aabbbbaaa</td></tr>
</table>
If you have width: 100%; you need to add margin-top:10px for example.

How to put a shadow around each row with different sizes?

I have a table that appears to have rows with different sizes. I would like to place a shadow box-shadow: 0 0 13px black around each blue border.
Simply putting the shadow on tr obviously doesn't do it:
I have tried to play with the shadow on td but without success, mostly because the shadow bleeds between cells.
Any ways to do that?
My code below.
<table>
<tbody>
<tr class="A">
<td>A1</td><td>A2</td><td>A3</td><td>A4</td>
</tr>
<tr class="B">
<td></td><td>B2</td><td>B3</td><td>B4</td>
</tr>
<tr class="C">
<td></td><td></td><td>C3</td><td>C4</td>
</tr>
<tr class="D">
<td>D1</td><td>D2</td><td>D3</td><td>D4</td>
</tr>
</tbody>
</table>
table {
border-collapse: separate;
border-spacing: 0 20px;
width: 300px;
text-align: center;
}
tr {
height: 40px;
/* box-shadow: 0 0 13px black; */
}
td {
border-top: 2px solid blue;
border-bottom: 2px solid blue;
}
td:last-child {
border-right: 2px solid blue;
}
.A td:nth-child(1) {border-left: 2px solid blue;}
.B td:nth-child(1) {border: none;}
.B td:nth-child(2) {border-left: 2px solid blue;}
.C td:nth-child(1) {border: none;}
.C td:nth-child(2) {border: none;}
.C td:nth-child(3) {border-left: 2px solid blue;}
.D td:nth-child(1) {border-left: 2px solid blue;}
You have to use the CSS filter property on the tr element to make shadows as you wanted.
CSS shadow on tr element
tr {filter: drop-shadow(5px 5px 5px #222222);}
Im pretty sure you can't do it without javascript because you need extra element between rows. You can do it like this:
$("tr").each(function() {
$("<div class='clearfix'></div>").insertBefore(this);
})
table, tr, td {
box-sizing:border-box;
}
.clearfix:before, .clearfix:after {
content: '.';
display: block;
overflow: hidden;
visibility: hidden;
font-size: 0;
line-height: 0;
width: 0;
height: 0;
}
.clearfix:after {
clear: both;
}
table {
border:2px solid #0f0;
padding:0 10px;
}
table tr {
float:right;
box-shadow:0px 0px 10px rgba(0,0,0,0.4);
margin:10px 0;
}
table td {
width:100px;
text-align:center;
border:2px solid #f00;
}
table td:empty {
display:none;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table>
<tbody>
<tr class="A">
<td>A1</td><td>A2</td><td>A3</td><td>A4</td>
</tr>
<tr class="B">
<td></td><td>B2</td><td>B3</td><td>B4</td>
</tr>
<tr class="C">
<td></td><td></td><td>C3</td><td>C4</td>
</tr>
<tr class="D">
<td>D1</td><td>D2</td><td>D3</td><td>D4</td>
</tr>
</tbody>
</table>

CSS border not applying to table

Changes to my table info on my CSS sheet doesn't seem to be changing when I run run the application. The CSS is mostly pre-generated from when I created the MVC. I just want tables to have borders so I added the "border: solid 2px black" portion. However it doesn't seem to be adding the border. What am I doing wrong here? CSS:
table {
margin-top: 0.75em;
border: solid 2px black;
}
th {
font-size: 1.2em;
text-align: left;
padding-left: 0;
}
th a {
display: block;
position: relative;
}
th a:link,
th a:visited,
th a:active,
th a:hover {
color: #333;
font-weight: 600;
text-decoration: none;
padding: 0;
}
th a:hover {
color: #000;
}
th.asc a,
th.desc a {
margin-right: .75em;
}
th.asc a:after,
th.desc a:after {
display: block;
position: absolute;
right: 0em;
top: 0;
font-size: 0.75em;
}
th.asc a:after {
content: '▲';
}
th.desc a:after {
content: '▼';
}
td {
padding: 0.25em 2em 0.25em 0em;
border: 0 none;
}
tr.pager td {
padding: 0 0.25em 0 0;
}
<table>
<tr>
<th>
Project ID
</th>
<th>
Test1
</th>
<th>
Test2
</th>
<th>
Test3
</th>
<th>
Test4
</th>
<th>
Test5
</th>
</tr>
</table>
I run your code and table has border!
Maybe there is another css code which Violates your style, so use !important
border: solid 2px black !important;
if you want to border every cell use this code
table, th, td {
border: 1px solid black;
border-collapse: collapse;}
I found the problem, and it's pretty stupid. I needed to refresh the cache (Ctrl + F5). It resulted in the changed CSS.

Trying to center 2 responsive tables on center of page

For some reason these 2 tables won't center, I tried the bootstrap container class, tried margin 0 auto. But they won't center smack in the middle, any idea?
I want both tables centered and displayed horizontally in the middle side by side.
It's on codepen over here:
enter link description here
http://codepen.io/Satearn/pen/ybvXLR
.z
{position :absolute ;
top:50%;
left:50%;
transform :translate(-50%,-50%) ;}
To centre align them just remove width: 100%; from your following CSS code.
.table-fill {
background: white;
border-radius:3px;
border-collapse: collapse;
height: 320px;
margin: auto;
max-width: 300px;
padding:5px;
width: 100%;
box-shadow: 0 5px 10px rgba(0, 0, 0, 0.1);
animation: float 5s infinite;
}
Like this? I used Bootstrap. And I reduced the data inside the table for simplicity
html {
background-color: #3e94ec;
}
/*** Table Styles **/
.table-fill {
border-radius: 3px;
border-collapse: collapse;
padding: 5px;
}
th {
color: #D5DDE5;
background: #1b1e24;
border-bottom: 4px solid #9ea7af;
border-right: 1px solid #343a45;
font-size: 23px;
font-weight: 100;
padding: 24px;
text-align: left;
text-shadow: 0 1px 1px rgba(0, 0, 0, 0.1);
vertical-align: middle;
}
th:first-child {
border-top-left-radius: 3px;
}
th:last-child {
border-top-right-radius: 3px;
border-right: none;
}
tr {
border-top: 1px solid #C1C3D1;
border-bottom-: 1px solid #C1C3D1;
color: #666B85;
font-size: 16px;
font-weight: normal;
text-shadow: 0 1px 1px rgba(256, 256, 256, 0.1);
}
tr:hover td {
background: #4E5066;
color: #FFFFFF;
border-top: 1px solid #22262e;
border-bottom: 1px solid #22262e;
}
tr:first-child {
border-top: none;
}
tr:last-child {
border-bottom: none;
}
tr:nth-child(odd) td {
background: #EBEBEB;
}
tr:nth-child(odd):hover td {
background: #4E5066;
}
tr:last-child td:first-child {
border-bottom-left-radius: 3px;
}
tr:last-child td:last-child {
border-bottom-right-radius: 3px;
}
td {
background: #FFFFFF;
padding: 20px;
text-align: left;
vertical-align: middle;
font-weight: 300;
font-size: 18px;
text-shadow: -1px -1px 1px rgba(0, 0, 0, 0.1);
border-right: 1px solid #C1C3D1;
}
td:last-child {
border-right: 0px;
}
th.text-left {
text-align: left;
}
th.text-center {
text-align: center;
}
th.text-right {
text-align: right;
}
td.text-left {
text-align: left;
}
td.text-center {
text-align: center;
}
td.text-right {
text-align: right;
}
.middlepage {
margin: 0 auto;
}
#outer-cont {
text-align: center;
}
#target-element-to-center {
display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<div class="container-fluid">
<div class="row">
<table class="table-fill col-xs-6" id="a">
<thead>
<tr>
<th class="text-center" colspan="2">Month</th>
</tr>
</thead>
<tbody class="table-hover">
<tr>
<td class="text-left">January</td>
<td class="text-left">$ 50,000.00</td>
</tr>
</tbody>
</table>
<table class="table-fill col-xs-6" id="a">
<thead>
<tr>
<th class="text-center" colspan="2">Strategies</th>
</tr>
</thead>
<tbody class="table-hover">
<tr>
<td class="text-left">January</td>
<td class="text-left">$ 50,000.00</td>
</tr>
</tbody>
</table>
</div>
</div>

Trouble changing the style on a table within a div statement

I created a table in HTML5 and used CSS to make it pretty. Then I decided to add a scroll bar and used webkit to change the style of that. Now after I used a div to get my scroll bar working it seems like my CSS code for the tbody,tr,thead,etc. are not working. I was wondering what I am doing wrong. I am positive that I am not calling the html table attributes correctly. I am very new to html5 and css but would really like to learn more.
Here is my code:
UPDATED 7/11/2013 9:36pm
CSS CODE
::-webkit-scrollbar {
width: 12px;
color:crimson;
background-color: black;
border-radius: 10px;
}
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
border-radius: 10px;
background-color:black;
}
::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
background-color:gray;
}
.mytablecontainer #mytable{
width:500px;
border-collapse:separate;
background:crimson;
border-radius: 15px;
}
.mytablecontainer tbody {
overflow: auto;
height: 150px;
float: left;
width: 100%;
}
.mytablcontainer #mytable td {
text-align:center;
background:gray;
border-bottom:5px solid black;
border-radius: 15px;
}
.mytablecontainer #mytable th {
font-weight:bold;
text-align:center;
background:crimson;
border-bottom:5px solid black;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
float: left;
width: 100%;
}
.mytablecontainer #mytable tr {
width: 100%;
display: table;
}
HTML5 CODE
<div class="mytablecontainer">
<table id="mytable">
<thead>
<tr>
<span>
Playlist
</span>
</tr>
</thead>
<tbody>
<tr>
<td> <span>
LINK 1
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 2
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 3
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 4
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 5
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 6
</span>
</td>
</tr>
<tr>
<td> <span>
LINK 7
</span>
</td>
</tr>
</tbody>
</table>
</div>
.mytablcontainer #mytable.td {} remove "." dot before td and correct the spelling of your class
.mytablecontainer #mytable td {}
Demo
you do not need to call each time your main div selector try this css
::-webkit-scrollbar {
width: 12px;
color:crimson;
background-color: black;
border-radius: 10px;
}
::-webkit-scrollbar-track {
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.3);
border-radius: 10px;
background-color:black;
}
::-webkit-scrollbar-thumb {
border-radius: 10px;
-webkit-box-shadow: inset 0 0 6px rgba(0,0,0,0.5);
background-color:gray;
}
.mytablecontainer #mytable{
width:500px;
border-collapse:separate;
background:crimson;
border-radius: 15px;
}
#mytable tbody {
overflow: auto;
height: 150px;
float: left;
width: 100%;
}
#mytable td {
text-align:center;
background:gray;
border-bottom:5px solid black;
border-radius: 15px;
}
#mytable th {
font-weight:bold;
text-align:center;
background:crimson;
border-bottom:5px solid black;
border-top-left-radius: 15px;
border-top-right-radius: 15px;
float: left;
width: 100%;
}
#mytable tr {
width: 100%;
display: table;
}
for multiple attribute use this:
#mytable table, #mytable th, #mytable td {
border: 1px solid black;
border-collapse: collapse;
}

Resources