My psd is like this
I want to add triangle in table cell only for active sort with css.
But I see this demo.
But I want the triangle to fall in the middle under the table title.
.table-bordered th {
background-color: #24374a;
border: 0;
color: #ffffff;
cursor: pointer;
}
.table-bordered th.active {
background-color: #041323;
position: relative;
}
.table-bordered th.active:after {
content: "";
position: absolute;
top: 0;
right: 0;
width: 0;
height: 0;
display: block;
border-left: 20px solid transparent;
border-bottom: 20px solid transparent;
border-top: 20px solid #f27e0a;
margin: auto;
}
<table class="table table-bordered" id="domainTable">
<thead>
<tr>
<th class="active" onclick="sortTable(0)">دامنه های تجاری</th>
<th onclick="sortTable(1)">دامنه های ارزان قیمت</th>
<th onclick="sortTable(2)">دامنه های ملی</th>
<th onclick="sortTable(3)">دامنه های خدماتی</th>
<th onclick="sortTable(4)">دامنه های کشوری</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
The result you wanted.
.table-bordered th {
background-color: #24374a;
border: 0;
color: #ffffff;
cursor: pointer;
height: 100px;
width: 150px;
}
.table-bordered th.active {
background-color: #041323;
position: relative;
}
.table-bordered th.active:after {
content: "";
position: absolute;
top: 55%;
left: 0;
right: 0;
transform: rotate(45deg);
height: 20px;
width: 20px;
border-bottom: 5px solid #f27e0a;
border-right: 5px solid #f27e0a;
margin-left: auto;
margin-right: auto;
}
<table class="table table-bordered" id="domainTable">
<thead>
<tr>
<th class="active" onclick="sortTable(0)">دامنه های تجاری</th>
<th onclick="sortTable(1)">دامنه های ارزان قیمت</th>
<th onclick="sortTable(2)">دامنه های ملی</th>
<th onclick="sortTable(3)">دامنه های خدماتی</th>
<th onclick="sortTable(4)">دامنه های کشوری</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
.triangle {
position: absolute;
top: 80%;
right: 50%;
float: right;
width: 0;
height: 0;
border-right: 10px solid transparent;
border-bottom: 10px solid red;
transform: rotate(-45deg);
}
td {
border: solid 3px black;
width: 160px;
height: 100px;
position: relative;
}
<table class="table">
<tbody>
<tr>
<td>
<div class="triangle"></div>Make Edits accordingly
</td>
</tr>
</tbody>
</table>
Related
I coded a table and this table has so much information in it that if the page is on 100% more than half of the table is missing.
I hope you can help me. You have to add more of the table cells to recreate it.
body {
min-height: 100vh;
background-color: var(--body-color);
transition: var(--tran-05);
background-color: #18191a;
--body-color: #18191a;
--sidebar-color: #242526;
--primary-color: #3a3b3c;
--primary-color-light: #3a3b3c;
--toggle-color: #fff;
--text-color: #ccc;
}
table.content {
border-collapse: collapse;
margin: auto;
min-width: 400px;
border-radius: 5px 5px 0 0;
justify-content: center;
width: 75%;
padding: 2%;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
color: #201f1b;
}
table.content thead tr {
background-color: #403f46;
color: white;
font-weight: bold;
text-align: left;
}
table.content th,
table.content td {
padding: 12px 16px;
}
table.content tbody tr {
border-bottom: 1px solid #ccc;
}
table.content tbody tr:last-of-type {
border-bottom: 2px solid #403f46;
}
table.content tbody tr.active {
font-weight: bold;
color: #403f46;
}
<table class="content">
<thead>
<tr>
<th>ServerID</th>
<th>Server Owner</th>
<th>Premium Server</th>
<th>Dev Server</th>
</tr>
</thead>
<tbody>
<tr>
<td style='color: white'><b>Test</b></td>
<td style='color: white'><b>Test</b></td>
<td style='color: white'><b>Test</b></td>
<td style='color: white'><b>Test</b></td>
</tr>
</tbody>
</table>
The problem is because of this:
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
it calculates -50% on the y-axis, which results in a cut. This works fine, but not for long elements.
Instead of this, just using a div as a wrapper around the table.
Update your code like the following:
Html:
<div class="wrapper">
<table class="content">
<thead>
<tr>
<th>ServerID</th>
<th>Server Owner</th>
<th>Premium Server</th>
<th>Dev Server</th>
</tr>
</thead>
<tbody>
<tr>
<td style='color: white'><b>Test</b></td>
<td style='color: white'><b>Test</b></td>
<td style='color: white'><b>Test</b></td>
<td style='color: white'><b>Test</b></td>
</tr>
</tbody>
</table>
</div>
css:
div.wrapper {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
table.content {
border-collapse: collapse;
margin: auto;
min-width: 400px;
border-radius: 5px 5px 0 0;
width: 75%;
padding: 2%;
color: #f9f9f9;
}
now it should work correctly.
i have big challenge in html css in create custom table
I have no idea in this case for create
I want create circular on vertical line of border
I create this table . but these to are very Different :-D
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
.container {
width: 100px;
height: 1px;
background-color: black;
position: relative;
}
.circle {
display: inline-block;
vertical-align: middle;
width: 40px;
height: 40px;
background-color: white;
border: solid 1px black;
border-radius: 50%;
position: absolute;
top: -6px;
left: calc(50% - 5px);
}
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Eve</td>
<td>
<div class="container">
<div class="circle">test</div>
</div>
</td>
<td>94</td>
</tr>
</table>
You are on right track just a little bit of changes in left and some padding on td
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
th, td {
padding: 16px;
}
td{
padding-right: 22px;
}
.container {
position: relative;
}
.circle {
display: inline-block;
vertical-align: middle;
width: 40px;
height: 40px;
background-color: white;
border: solid 1px black;
border-radius: 50%;
position: absolute;
left: -38px;
top: 50%;
text-align: center;
line-height: 37px;
transform: translate(0%, -50%);
}
<html>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Eve</td>
<td><div class="container">
<div class="circle">
test
</div>
</div></td>
<td>94</td>
</tr>
<tr>
<td>Eve</td>
<td><div class="container">
<div class="circle">
test
</div>
</div></td>
<td>94</td>
</tr>
<tr>
<td>Eve</td>
<td><div class="container">
<div class="circle">
test
</div>
</div></td>
<td>94</td>
</tr>
</table>
</html>
this code
try that :
<html>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Eve</td>
<td style="width: 100px;height: 100px;"> <div class="row">
<div class="large-8 large-centered">
<div class="wrapper">
<div class="vertical-line"></div>
<div class="circle">
<h5>Some Text</h5>
</div>
<div class="vertical-line"></div>
</div>
</div>
</div>
</td>
<td>94</td>
</tr>
</table>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
.wrapper {
width: auto;
height: auto;
}
.circle {
width: 50px;
height: 50px;
border-style: solid;
border-color: #000000;
border-radius: 100px;
position: relative;
margin: 0 auto 0 auto;
}
h5 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
margin: 0;
color: #000000;
}
.vertical-line {
width: 2px;
height: 100px;
background: #2ecc71;
margin: 0 auto 0 ;
}
hr {
border: 0;
height: 1px;
background: #333;
background: linear-gradient(to right, #ccc, #333, #ccc);
}
</style>
</html>
Make sure the container is of 100% and that left is correct:
<html>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Eve</td>
<td><div class="container">
<div class="circle">
test
</div>
</div></td>
<td>94</td>
</tr>
</table>
<style>
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
.container {
width: 100%;
height: 1px;
background-color: black;
position: relative;
}
.circle {
display: inline-block;
vertical-align: middle;
width: 40px;
height: 40px;
background-color: white;
border: solid 1px black;
border-radius: 50%;
position: absolute;
top: -6px;
left: -20px;
}
</style>
</html>
How about something like this? Note that in order for this to work reliably, I gave your table row (the tr element) a fixed height.
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
tr {
height: 10px;
}
.firstRow {
position: relative;
background-color: red;
}
.circle {
position:absolute;
width: 40px;
height: 40px;
background-color: white;
border: solid 1px black;
border-radius: 50%;
top: -30px;
transform: translateX(-50%);
left: calc(100%);
}
.circleText {
text-align: center;
display: block;
left: 50%;
top: 20px;
transform: translateY(50%);
}
<html>
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Eve
<div class="firstRow">
<div class="circle">
<div class="circleText">test</span>
</div>
</div>
</td>
<td>Eve's last name</td>
<td>94</td>
</tr>
</table>
</html>
I created a working demo. It is fully working.
table, th, td {
border: 1px solid black;
border-collapse: collapse;
}
.main-container{
display:flex;
width:100%;
}
.container {
display:flex;
justify-content: center;
flex-direction:column;
align-items:center;
flex:2;
}
.container:before, .container:after {
content: "";
background: #000;
width: 1px;
height: 20px;
}
.circle {
width: 40px;
height: 40px;
background-color: white;
border: solid 1px black;
border-radius: 50%;
display:flex;
justify-content: center;
align-items:center;
}
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
</tr>
<tr>
<td>Eve</td>
<td>
<div class="main-container">
<div style="flex:1">
<div>Monday</div>
<div>March 6, 2020</div>
<div>from Tokyo</div>
</div>
<div class="container">
<div class="circle">test</div>
</div>
<div>
<div>Monday</div>
<div>March 6, 2020</div>
<div>from Tokyo</div>
</div>
</div>
</td>
<td>94</td>
</tr>
</table>
The key lessons here are:
an extra relatively positioned element is not necessary for absolutely positioning the circle. we can just put the position: relative on the <td> itself.
use transform: translate() to position the circle elements without need for arbitrary pixel values
This solution uses the least CSS possible and standard (semantic) <table> markup
table {
border-collapse: collapse;
width: 100%;
}
td, th {
border: solid 1px #666;
padding: 2em 4em;
position: relative;
}
.circle {
font-size: 0.75em;
background: #fff;
border: solid 1px #aaa;
border-radius: 50%;
width: 4em;
height: 4em;
box-shadow: 1px 1px 4px #aaa;
display: flex;
align-items: center;
text-align: center;
justify-content: center;
position: absolute;
z-index: 1;
top: 50%;
right: 0;
transform: translate(50%, -50%);
}
<table>
<tr>
<td>XYZ</td>
<td>
MAR 2
<span class="circle">
10<br>Days
</span>
</td>
<td>MAR 11</td>
<td>9</td>
</tr>
<tr>
<td>ABC</td>
<td>
MAR 6
<span class="circle">
20<br>Days
</span>
</td>
<td>MAR 15</td>
<td>11</td>
</tr>
</table>
Codepen
I'm trying to create two sticky columns that scroll horizontally through the tables. The first column behaves properly but the second column is transparent and sits on top of the other columns and rows in the table when you scroll. I've tried adjusting the padding and position properties but I cant seem to get my columns to scroll properly through the table.
I am using https://jsfiddle.net/zinoui/BmLpV/ as a reference.
.zui-table {
border: none;
border-right: solid 1px #DDEFEF;
border-collapse: separate;
border-spacing: 0;
font: normal 13px Arial, sans-serif;
}
.zui-table thead th {
background-color: #DDEFEF;
border: none;
color: #336B6B;
padding: 10px;
text-align: left;
text-shadow: 1px 1px 1px #fff;
white-space: nowrap;
}
.zui-table tbody td {
border-bottom: solid 1px #DDEFEF;
color: #333;
padding: 10px;
text-shadow: 1px 1px 1px #fff;
white-space: nowrap;
}
.zui-wrapper {
position: relative;
}
.zui-scroller {
margin-left: 141px;
overflow-x: scroll;
overflow-y: visible;
padding-bottom: 5px;
width: 300px;
}
.zui-table .zui-sticky-col1 {
border-left: solid 1px #DDEFEF;
border-right: solid 1px #DDEFEF;
left: 0;
position: absolute;
top: auto;
width: 120px;
}
.zui-table .zui-sticky-col2 {
border-left: solid 1px #DDEFEF;
border-right: solid 1px #DDEFEF;
left: 20;
position: absolute;
top: auto;
width: 60px;
}
<div class="zui-wrapper">
<div class="zui-scroller">
<table class="zui-table">
<thead>
<tr>
<th class="zui-sticky-col1">Name</th>
<th class="zui-sticky-col2">Number</th>
<th>Position</th>
<th>Height</th>
<th>Born</th>
<th>Salary</th>
<th>Prior to NBA/Country</th>
</tr>
</thead>
<tbody>
<tr>
<td class="zui-sticky-col1">DeMarcus Cousins</td>
<td class="zui-sticky-col2">15</td>
<td>C</td>
<td>6'11"</td>
<td>08-13-1990</td>
<td>$4,917,000</td>
<td>Kentucky/USA</td>
</tr>
<tr>
<td class="zui-sticky-col1">Isaiah Thomas</td>
<td class="zui-sticky-col2">22</td>
<td>PG</td>
<td>5'9"</td>
<td>02-07-1989</td>
<td>$473,604</td>
<td>Washington/USA</td>
</tr>
<tr>
<td class="zui-sticky-col1">Ben McLemore</td>
<td class="zui-sticky-col2">16</td>
<td>SG</td>
<td>6'5"</td>
<td>02-11-1993</td>
<td>$2,895,960</td>
<td>Kansas/USA</td>
</tr>
</tbody>
</table>
</div>
</div>
Try this:
.zui-table .zui-sticky-col-next {
border-left: solid 1px #DDEFEF;
border-right: solid 1px #DDEFEF;
left: 100;
position: absolute;
top: auto;
width: 50px;
}
.zui-table tbody td {
background-color: #fff;
}
then add the next class in each HTML Column:
<div class="zui-wrapper">
<div class="zui-scroller">
<table class="zui-table">
<thead>
<tr>
<th class="zui-sticky-col">Name</th>
<th class="zui-sticky-col-next">Number</th>
<th>Position</th>
<th>Height</th>
<th>Born</th>
<th>Salary</th>
<th>Prior to NBA/Country</th>
</tr>
</thead>
<tbody>
<tr>
<td class="zui-sticky-col">DeMarcus Cousins</td>
<td class="zui-sticky-col-next">15</td>
<td>C</td>
<td>6'11"</td>
<td>08-13-1990</td>
<td>$4,917,000</td>
<td>Kentucky/USA</td>
</tr>
<tr>
<td class="zui-sticky-col">Isaiah Thomas</td>
<td class="zui-sticky-col-next">22</td>
<td>PG</td>
<td>5'9"</td>
<td>02-07-1989</td>
<td>$473,604</td>
<td>Washington/USA</td>
</tr>
<tr>
<td class="zui-sticky-col">Ben McLemore</td>
<td class="zui-sticky-col-next">16</td>
<td>SG</td>
<td>6'5"</td>
<td>02-11-1993</td>
<td>$2,895,960</td>
<td>Kansas/USA</td>
</tr>
<tr>
<td class="zui-sticky-col">Marcus Thornton</td>
<td class="zui-sticky-col-next">23</td>
<td>SG</td>
<td>6'4"</td>
<td>05-05-1987</td>
<td>$7,000,000</td>
<td>Louisiana State/USA</td>
</tr>
<tr>
<td class="zui-sticky-col">Jason Thompson</td>
<td class="zui-sticky-col-next">34</td>
<td>PF</td>
<td>6'11"</td>
<td>06-21-1986</td>
<td>$3,001,000</td>
<td>Rider/USA</td>
</tr>
</tbody>
</table>
</div>
</div>
.zui-table {
border: none;
border-right: solid 1px #DDEFEF;
border-collapse: separate;
border-spacing: 0;
font: normal 13px Arial, sans-serif;
}
.zui-table thead th {
background-color: #DDEFEF;
border: none;
color: #336B6B;
padding: 10px;
text-align: left;
text-shadow: 1px 1px 1px #fff;
white-space: nowrap;
}
.zui-table tbody td {
border-bottom: solid 1px #DDEFEF;
color: #333;
padding: 10px;
text-shadow: 1px 1px 1px #fff;
white-space: nowrap;
}
.zui-wrapper {
position: relative;
}
.zui-scroller {
margin-left: 141px;
overflow-x: scroll;
overflow-y: visible;
padding-bottom: 5px;
width: 300px;
}
.zui-table .zui-sticky-col {
border-left: solid 1px #DDEFEF;
border-right: solid 1px #DDEFEF;
left: 0;
position: absolute;
top: auto;
width: 120px;
}
.zui-table .zui-sticky-col-next {
border-left: solid 1px #DDEFEF;
border-right: solid 1px #DDEFEF;
left: 100;
position: absolute;
top: auto;
width: 50px;
}
.zui-table tbody td {
background-color: #fff;
}
<div class="zui-wrapper">
<div class="zui-scroller">
<table class="zui-table">
<thead>
<tr>
<th class="zui-sticky-col">Name</th>
<th class="zui-sticky-col-next">Number</th>
<th>Position</th>
<th>Height</th>
<th>Born</th>
<th>Salary</th>
<th>Prior to NBA/Country</th>
</tr>
</thead>
<tbody>
<tr>
<td class="zui-sticky-col">DeMarcus Cousins</td>
<td class="zui-sticky-col-next">15</td>
<td>C</td>
<td>6'11"</td>
<td>08-13-1990</td>
<td>$4,917,000</td>
<td>Kentucky/USA</td>
</tr>
<tr>
<td class="zui-sticky-col">Isaiah Thomas</td>
<td class="zui-sticky-col-next">22</td>
<td>PG</td>
<td>5'9"</td>
<td>02-07-1989</td>
<td>$473,604</td>
<td>Washington/USA</td>
</tr>
<tr>
<td class="zui-sticky-col">Ben McLemore</td>
<td class="zui-sticky-col-next">16</td>
<td>SG</td>
<td>6'5"</td>
<td>02-11-1993</td>
<td>$2,895,960</td>
<td>Kansas/USA</td>
</tr>
<tr>
<td class="zui-sticky-col">Marcus Thornton</td>
<td class="zui-sticky-col-next">23</td>
<td>SG</td>
<td>6'4"</td>
<td>05-05-1987</td>
<td>$7,000,000</td>
<td>Louisiana State/USA</td>
</tr>
<tr>
<td class="zui-sticky-col">Jason Thompson</td>
<td class="zui-sticky-col-next">34</td>
<td>PF</td>
<td>6'11"</td>
<td>06-21-1986</td>
<td>$3,001,000</td>
<td>Rider/USA</td>
</tr>
</tbody>
</table>
</div>
</div>
Try it, please
.zui-table tbody td {
background-color:#fff;
}
I have a table that I'm trying to get sticky headers, following this article. Except my table style has the headers with a border at the top and bottom.
The part I do not understand is that the top/bottom borders applied to the th scroll away with the rest of the table instead of staying with the "stuck" header cells. Is there anything that can be done about this?
Working sample can be found here: https://codepen.io/smlombardi/pen/MNKqQY?editors=1100#0
let string = ''
console.log("oj")
for(let i=0; i<100; i++) {
string += `
<tr>
<td>Malcolm Reynolds</td>
<td>Captain</td>
<td>9035749867</td>
<td>mreynolds</td>
</tr>
`
}
document.getElementsByTagName('tbody')[0].innerHTML += string
.table-sticky-container {
height: 200px;
overflow-y: scroll;
border-top: 1px solid green;
border-bottom: 1px solid green;
}
.table-sticky {
th {
position: sticky;
top: 0;
z-index: 2;
border-top: 1px solid red !important;
border-bottom: 2px solid red !important;
}
}
<div class="table-sticky-container">
<table class="table table-sticky">
<thead class="thead-light">
<tr>
<th scope="col">Name</th>
<th scope="col">Title</th>
<th scope="col">ID</th>
<th scope="col">Username</th>
</tr>
</thead>
<tbody>
<tr>
<td>Malcolm Reynolds</td>
<td>Captain</td>
<td>9035749867</td>
<td>mreynolds</td>
</tr>
</tbody>
</table>
</div>
You can add
.table {
border-collapse: separate;
}
But unfortunately it looks bad, a better solution will be adding a workaround using a pseudo-element.
th:after,
th:before {
content: '';
position: absolute;
left: 0;
width: 100%;
}
th:before {
top: -1px;
border-top: 1px solid red;
}
th:after {
bottom: -1px;
border-bottom: 2px solid red;
}
.table-sticky-container {
height: 200px;
overflow-y: scroll;
border-top: 1px solid green;
border-bottom: 1px solid green;
}
.table-sticky th {
position: -webkit-sticky;
position: sticky;
top: 0;
z-index: 2;
}
th:after,
th:before {
content: '';
position: absolute;
left: 0;
width: 100%;
}
th:before {
top: -1px;
border-top: 1px solid red;
}
th:after {
bottom: -1px;
border-bottom: 2px solid red;
}
<link rel='stylesheet' href='https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css'>
<div class="table-sticky-container">
<table class="table table-sticky">
<thead class="thead-light">
<tr>
<th scope="col">Name</th>
<th scope="col">Title</th>
<th scope="col">ID</th>
<th scope="col">Username</th>
</tr>
</thead>
<tbody>
<tr>
<td>Malcolm Reynolds</td>
<td>Captain</td>
<td>9035749867</td>
<td>mreynolds</td>
</tr>
<tr>
<td>Zoe Washburne</td>
<td>First Officer</td>
<td>8908980980</td>
<td>zwashburne</td>
</tr>
<tr>
<td>Kaylee Frye</td>
<td>Engineer</td>
<td>6678687678</td>
<td>kfrye</td>
</tr>
<tr>
<td>Malcolm Reynolds</td>
<td>Captain</td>
<td>9035749867</td>
<td>mreynolds</td>
</tr>
<tr>
<td>Zoe Washburne</td>
<td>First Officer</td>
<td>8908980980</td>
<td>zwashburne</td>
</tr>
<tr>
<td>Kaylee Frye</td>
<td>Engineer</td>
<td>6678687678</td>
<td>kfrye</td>
</tr>
</tbody>
</table>
</div>
The second solution
.table {
border-collapse: collapse;
}
.table-sticky thead th {
position: -webkit-sticky;
position: sticky;
top: 0;
z-index: 2;
box-shadow: inset 0 1px 0 red, inset 0 -2px 0 red;
}
You can add
.table {
border-collapse: separate;
border-spacing: 0;
}
Don't use border-collapse and draw the lines as follows :
td, th {
border-bottom: 1px solid grey;
border-right: 1px solid grey;
}
table {
border-spacing: 0px;
border-left: 1px solid grey
}
th {
background-color:#c5e8ec;
position: sticky;
position: -webkit-sticky;
border-top: 1px solid grey;
top:0;
}
Another working solution (tested at latest Chrome and FF) - wrap th/td content with divs and use those divs borders instead of cell's borders.
<div class="wrapper">
<table>
<thead>
<tr>
<th>
<div class="cell">head1</div>
</th>
<th>
<div class="cell">head2</div>
</th>
<th>
<div class="cell">head3</div>
</th>
<th>
<div class="cell">head4</div>
</th>
<th>
<div class="cell">head5</div>
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div class="cell">1</div>
</td>
<td>
<div class="cell">1</div>
</td>
<td>
<div class="cell">1</div>
</td>
<td>
<div class="cell">1</div>
</td>
<td>
<div class="cell">1</div>
</td>
</tr>
<tr>
<td>
<div class="cell">1</div>
</td>
<td>
<div class="cell">1</div>
</td>
<td>
<div class="cell">1</div>
</td>
<td>
<div class="cell">1</div>
</td>
<td>
<div class="cell">1</div>
</td>
</tr>
<tr>
<td>
<div class="cell">1</div>
</td>
<td>
<div class="cell">1</div>
</td>
<td>
<div class="cell">1</div>
</td>
<td>
<div class="cell">1</div>
</td>
<td>
<div class="cell">1</div>
</td>
</tr>
</tbody>
</table>
</div>
table {
border-collapse: collapse;
table-layout: fixed;
width: 500px;
}
.wrapper {
height: 150px;
overflow: auto;
}
td, th {
width: 150px;
height: 50px;
text-align: center;
font-size: 32px;
padding: 0;
}
th {
position: sticky;
top: 0;
left: 0;
background-color: #fff;
}
.cell {
border: 1px solid black;
height: 100%;
}
td .cell {
border-top: none;
border-left: none;
}
th .cell {
border-left: none;
}
td:first-child .cell,
th:first-child .cell {
border-left: 1px solid black;
}
I have a table that looks like this:
And every row has a hidden details field:
So I want to remove border spacing from row and its details row.. How can I do that?
this is my HTML:
<table class="table message-table">
<thead>
<tr>
<th>Title</th>
<th>Date</th>
<th>Action</th>
<th></th>
</tr>
</thead>
<tbody>
<ng-container *ngFor="let message of messages | paginate: config">
<tr>
<td>{{message.title}}</td>
<td>{{message.created | date:'longDate'}}</td>
<td (click)="message.collapsed = !message.collapsed; makeMessageSeen(message);" [attr.aria-expanded]="!message.collapsed" aria-controls="collapseExample">{{message.collapsed ? 'More' : 'Less'}}</td>
<td></td>
</tr>
<tr id="collapseExample" [ngbCollapse]="message.collapsed">
<td>{{message.text}}</td>
<td colspan="3"></td>
</tr>
</ng-container>
</tbody>
</table>
and this is my SCSS:
.messages {
background-color: $color-background-main;
min-height: 17rem;
overflow-x: auto;
padding-top: 2rem;
.message-table {
border-collapse: separate;
border-spacing: 0 0.4rem;
thead {
th {
border: none;
font-size: 0.6rem;
color: #9b9b9b;
text-transform: uppercase;
padding-top: 0;
padding-bottom: 0;
&:first-child {
width: 70%;
padding-left: 1rem;
}
}
}
}
tbody {
tr {
box-shadow: $main-shadow;
background-color: white;
&.selected {
box-shadow: $shadow-selected;
}
td:first-child {
padding-left: 1rem;
}
}
td {
background-color: white;
border: none;
padding-top: 0;
padding-bottom: 0;
padding-right: 0;
height: 2.5rem;
vertical-align: middle;
table-layout: fixed;
&:first-child {
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
&:last-child {
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
padding-right: 0;
width: 2rem;
}
}
}
}
How can I fix this? I've tried making tr a top border but nothing happened... What are other solutions for my problem?
UPDATE 1
Adding codepen of a simple example : https://codepen.io/anon/pen/prxgOe
UPDATE 2
I want to remove spacing between title and details tr elements ONLY!
Here is a quick fix using borders.
table {
border-collapse: collapse;
border-spacing: 0 0.4rem;
}
tr {
background-color: #ccc;
}
.title {
border-top: 5px solid #fff;
}
.details {
/* display: none; */
}
<table>
<thead>
<tr>
<th>Title</th>
<th>Created</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr class="title">
<td>title1</td>
<td>2017-01-01</td>
<td>More</td>
</tr>
<tr class="details">
<td>this is text1</td>
<td colspan="2"></td>
</tr>
<tr class="title">
<td>title2</td>
<td>2017-01-01</td>
<td>More</td>
</tr>
<tr class="details">
<td>this is text2</td>
<td colspan="2"></td>
</tr>
<tr class="title">
<td>title3</td>
<td>2017-01-01</td>
<td>More</td>
</tr>
<tr class="details">
<td>this is text3</td>
<td colspan="2"></td>
</tr>
</tbody>
</table>
I think you want like this
table {
border-collapse: collapse;
border-spacing: 0 0.4rem;
}
tr {
background-color: #ccc;
display: table-row;
}
table {
border-collapse: collapse;
border-spacing: 0 0.4rem;
}
tr {
background-color: #ccc;
display: table-row;
}
.title:first-child {
border-top: 7px solid #fff;
}
.title {
border-top: 12px solid #fff;
}
tbody tr:nth-child(2n) {
position: relative;
}
tbody tr:nth-child(2n)::after {
bottom: 0;
box-shadow: 0 2px 2px 0 #ebebeb;
content: "";
height: 100%;
left: 0;
position: absolute;
right: 0;
width: 100%;
}
<table>
<thead>
<tr>
<th>Title</th>
<th>Created</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr class="title">
<td>title1</td>
<td>2017-01-01</td>
<td>More</td>
</tr>
<tr class="details">
<td>this is text1</td>
<td colspan="2"></td>
</tr>
<tr class="title">
<td>title2</td>
<td>2017-01-01</td>
<td>More</td>
</tr>
<tr class="details">
<td>this is text2</td>
<td colspan="2"></td>
</tr>
<tr class="title">
<td>title3</td>
<td>2017-01-01</td>
<td>More</td>
</tr>
<tr class="details">
<td>this is text3</td>
<td colspan="2"></td>
</tr>
</tbody>
</table>
*ngFor has an option to detect odd and even rows:
<div *ngFor="let message of messages; let odd=odd; let even=even>..</div>
then you can use odd or even values to set style/class as so:
<div [class.evenClass]="event" [class.oddClass]="odd">...</div>
and in the stylesheet, define .evenClass and .oddClass style as needed.
P.S.You have a table layout, you need to adapt above to your case
#hunzaboy and #ankitapatel answers were kind of good for me, but eventually I came with different solution which is probably not the best one, but it works like a charm... It does not break the ui scalability or anything else...
So I just added div elements in each of td elements so my HTML now looks like this:
<tbody>
<ng-container *ngFor="let message of messages | paginate: config">
<tr>
<td [class.unseen]="!message.seen" [class.seen]="message.seen">{{message.title}}</td>
<td [class.unseen]="!message.seen" [class.seen]="message.seen">{{message.created | date:'longDate'}}</td>
<td class="details-button" (click)="message.collapsed = !message.collapsed; makeMessageSeen(message);" [attr.aria-expanded]="!message.collapsed" aria-controls="collapseExample">{{message.collapsed ? 'More' : 'Less'}}</td>
<td></td>
</tr>
<tr id="collapseExample" [ngbCollapse]="message.collapsed">
<td>
<div class="text-container">{{message.text}}</div>
</td>
<td colspan="3">
<div class="empty-container"></div>
</td>
</tr>
</ng-container>
</tbody>
and then I added this SCSS to my file:
#collapseExample {
td {
padding: 0;
}
.text-container {
background-color: #fff;
margin-top: -23px;
padding-left: 1rem;
border-radius: 0.2rem;
height: 100%;
padding-bottom: 1rem;
}
.empty-container {
background-color: #fff;
height: 100%;
margin-top: -20px;
width: 100%;
}
}