CSS box-shadow on table rows - tr - doesn't seem to be working consistently across browsers. On some browsers the shadow is displayed; on others, there is no shadow.
I'm using the following CSS:
tr {
background-color: rgb(165, 182, 229);
box-shadow: 0px 2px 2px black;
-moz-box-shadow: 0px 2px 2px black;
-webkit-box-shadow: 0px 2px 2px black;
}
td, th {
padding: 5px;
text-align: left;
}
Here is a jsFiddle of the below snippet:
tr {
background-color: rgb(165, 182, 229);
box-shadow: 0px 2px 2px black;
-moz-box-shadow: 0px 2px 2px black, ;
-webkit-box-shadow: 0px 2px 2px black;
}
td, th {
padding: 5px;
text-align: left;
}
<table>
<tr>
<td> </td>
<th>One</th>
<th>Two</th>
</tr>
<tr>
<th>Title</th>
<td>Three</td>
<td>Four</td>
</tr>
<tr>
<th>Title2</th>
<td>Five</td>
<td>Six</td>
</tr>
<tr>
<th>Title3</th>
<td>Seven</td>
<td>Eight</td>
</tr>
<tr>
<th>Title4</th>
<td>Nine</td>
<td>Ten</td>
</tr>
</table>
Note: The same behavior is observed when substituting <tr> with <div> and adding display: table-row.
Use transform scale(1,1) property with box-shadow it will solve the problem.
tr:hover {
transform: scale(1);
-webkit-transform: scale(1);
-moz-transform: scale(1);
box-shadow: 0px 0px 5px rgba(0,0,0,0.3);
-webkit-box-shadow: 0px 0px 5px rgba(0,0,0,0.3);
-moz-box-shadow: 0px 0px 5px rgba(0,0,0,0.3);
}
Fiddle: https://jsfiddle.net/ampicx/5p91xr48/
Thanks!!
As previously mentioned, box-shadow property works only with elements that have display: block or display:inline-block property.
If you'll add display: block to the table cell as a general styling rule, it will collapse, since automatic width/height proportions that cells had with display:table won't be applied anymore. To simulate that behavior just assign min-width attribute to each th and td.
Then apply box-shadow to the row (on hover or without).
In summary, your code should look like this:
table { box-sizing: border-box; }
td, th { padding-left: 16px; min-width: 170px; text-align: left; }
tr { display: block; }
tr:hover { box-shadow: 0px 2px 18px 0px rgba(0,0,0,0.5); cursor: pointer; }
I've omitted vendor prefixes for simplicity.
Here is the full example:
table {
box-sizing: border-box;
border-bottom: 1px solid #e8e8e8;
}
td,
th {
padding-left: 16px;
min-width: 170px;
border: 1px solid #e8e8e8;
border-bottom: none;
font: 14px/40px;
text-align: left;
}
td {
color: #666;
}
tr {
display: block;
}
th {
color: #333;
}
tr:hover {
background-color: #fbfbfb;
box-shadow: 0px 2px 18px 0px rgba(0, 0, 0, 0.5);
cursor: pointer;
}
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>Phone number</th>
<th>Date</th>
<th>Name</th>
<th>Label</th>
</tr>
</thead>
<tbody>
<tr>
<td>0342443</td>
<td>10 August 2013</td>
<td>Kate</td>
<td>Loves cats</td>
</td>
<tr>
<td>0342442</td>
<td>9 August 2013</td>
<td>Mary</td>
<td>Boring</td>
</tr>
<tr>
<td>0342441</td>
<td>8 August 2013</td>
<td>Anna</td>
<td>Loves extreme stuff</td>
</tr>
</tbody>
</table>
You can also check out the fiddle here.
Please star this bug if you want to see it get fixed:
https://code.google.com/p/chromium/issues/detail?id=94871
If you want the table cell widths to continue to adjust themselves automatically, you can apply the shadow to the individual cells instead:
td:first-child {
box-shadow:
inset 0px 11px 8px -10px blue,
inset 0px -11px 8px -10px blue,
inset 11px 0px 8px -10px blue;
}
td {
box-shadow:
inset 0px 11px 8px -10px blue,
inset 0px -11px 8px -10px blue;
}
td:last-child {
box-shadow:
inset 0px 11px 8px -10px blue,
inset 0px -11px 8px -10px blue,
inset -11px 0px 8px -10px blue;
}
Full example here. (jsfiddle)
(Inspired by https://stackoverflow.com/a/10150898/724752)
In each box shadow value:
Adjust the 3rd number (blur radius) to change the blur radius.
The 4th number (spread radius) must always be negative and its absolute value must be greater than the 3rd number (blur radius).
Make the 1st number (offset x) nonzero to get a shadow on the left or right. Make its absolute value 1 greater than the absolute value of the 4th number (see the example above again, much easier to see what I mean).
Make the 2nd number (offset y) nonzero to get a shadow at top or bottom. Make its absolute value 1 greater than the absolute value of the 4th number.
I had the same issue. I was trying to highlight an entire row when the mouse was over it. Below is the css code for it:
tr:hover {
outline: none;
-webkit-box-shadow: inset 0 0 10px #337AB7;
box-shadow: inset 0 0 10px #337AB7;
}
It works fine on Mozilla Firefox (38.0.1) and Internet Explorer (11.0.9600.17801), both on Windows 7. However, did not work on Chrome (43.0.2357.81).
Therefore, I had to workaround and I did a mix of the answers of Sviatoslav Zalishchuk and David Winiecki. As an result I got:
#media screen and (-webkit-min-device-pixel-ratio:0) {
tr:hover td:first-child {
box-shadow: inset 0px 11px 8px -10px #337AB7,
inset 0px -11px 8px -10px #337AB7,
inset 11px 0px 8px -10px #337AB7;
}
tr:hover td {
box-shadow: inset 0px 11px 8px -10px #337AB7,
inset 0px -11px 8px -10px #337AB7;
}
tr:hover td:last-child {
box-shadow: inset 0px 11px 8px -10px #337AB7,
inset 0px -11px 8px -10px #337AB7,
inset -11px 0px 8px -10px #337AB7;
}
}
tbody > tr:hover {
outline: none;
-webkit-box-shadow: inset 0 0 10px #337AB7;
box-shadow: inset 0 0 10px #337AB7;
}
That works fine and it does not break the column width of the table and still working on Mozilla and Explorer.
Below there is a full example:
table {
box-sizing: border-box;
border-collapse: collapse;
}
td,
th {
padding-left: 10px;
padding-right: 10px;
border: 1px solid #dddddd;
font: 14px;
text-align: left;
}
/*To work only on Chrome and Safari*/
#media screen and (-webkit-min-device-pixel-ratio:0) {
tr:hover td:first-child {
box-shadow: inset 0px 11px 8px -10px #337AB7,
inset 0px -11px 8px -10px #337AB7,
inset 11px 0px 8px -10px #337AB7;
}
tr:hover td {
box-shadow: inset 0px 11px 8px -10px #337AB7,
inset 0px -11px 8px -10px #337AB7;
}
tr:hover td:last-child {
box-shadow: inset 0px 11px 8px -10px #337AB7,
inset 0px -11px 8px -10px #337AB7,
inset -11px 0px 8px -10px #337AB7;
}
}
/*To work on the others browsers*/
tbody > tr:hover {
outline: none;
-webkit-box-shadow: inset 0 0 10px #337AB7;
box-shadow: inset 0 0 10px #337AB7;
}
<table>
<thead>
<tr>
<th>Name</th>
<th>Born</th>
<th>City</th>
</tr>
</thead>
<tbody>
<tr>
<td>David Gilmour</td>
<td>6 March 1946</td>
<td>Cambridge, England</td>
</tr>
<tr>
<td>Roger Waters</td>
<td>6 September 1943</td>
<td>Surrey, England</td>
</tr>
<tr>
<td>Nick Mason</td>
<td>27 January 1944</td>
<td>Birmingham, England</td>
</tr>
<tr>
<td>Richard Wright</td>
<td>28 July 1943</td>
<td>London, England</td>
</tr>
</tbody>
</table>
I've got an effect quite similar to box-shadow using filter and drop-shadow. It's a bit hacky and you'll need to find the best configuration of the shadow to match your scenario though.
My original class:
.project-row {
box-shadow: 0 0 15px 0 black;
}
My new class:
.project-row {
filter: drop-shadow(0 0 9px black);
}
https://codepen.io/nico_nj/pen/XWbaZPJ
Reasons behind it seem down to default CSS - the display: block was the biggest factor.
CSS / HTML / Demo
tr {
background-color: rgb(165, 182, 229);
display: block;
margin-bottom: 5px;
-moz-box-shadow: 0px 2px 2px black;
-webkit-box-shadow: 0px 2px 2px black;
box-shadow: 0px 2px 2px black;
}
td,th {
padding: 5px;
text-align: left;
}
<table>
<tr>
<td> </td>
<th>One</th>
<th>Two</th>
</tr>
<tr>
<th>Title</th>
<td>Three</td>
<td>Four</td>
</tr>
<tr>
<th>Title2</th>
<td>Five</td>
<td>Six</td>
</tr>
<tr>
<th>Title3</th>
<td>Seven</td>
<td>Eight</td>
</tr>
<tr>
<th>Title4</th>
<td>Nine</td>
<td>Ten</td>
</tr>
</table>
Now, in v53 Chrome it fixed and box-shadow work fine for <tr></tr>!
CSS / HTML / Demo
table {
border-spacing: 0 10px;
border-collapse: separate;
}
tbody {
display: table-row-group;
vertical-align: middle;
}
tr {
margin-bottom: 9px;
}
tr:hover {
box-shadow: 0 5px 8px 0 rgba(50, 50, 50, 0.35);
-webkit-box-shadow: 0 5px 8px 0 rgba(50, 50, 50, 0.35);
-moz-box-shadow: 0 5px 8px 0 rgba(50, 50, 50, 0.35);
}
<table class="table">
<caption>Optional table caption.</caption>
<thead>
<tr>
<th>#</th>
<th>First Name</th>
<th>Last Name</th>
<th>Username</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Mark</td>
<td>Otto</td>
<td>#mdo</td>
</tr>
<tr>
<th scope="row">2</th>
<td>Jacob</td>
<td>Thornton</td>
<td>#fat</td>
</tr>
<tr>
<th scope="row">3</th>
<td>Larry</td>
<td>the Bird</td>
<td>#twitter</td>
</tr>
</tbody>
</table>
I wanted a box-shadow on the left side of the row when hovered:
I fixed it simply by setting the box-shadow on the first cell in the row. Like this:
tr:hover { background: #EEF0F3; cursor: pointer; }
tr:hover td:first-child { box-shadow: inset 2px 0 0 0 #323335; }
I've tried it in Firefox, Chrome, and IE9. Seems to work fine.
If you want a 1px wide border around the whole row you could do something like:
tr:hover td { box-shadow: 0 1px 0 0 black, 0 -1px 0 0 black; }
tr:hover td:first-child { box-shadow: 0 -1px 0 0 black, -1px 0 0 0 black, 0 1px 0 0 black; }
tr:hover td:last-child { box-shadow: 0 -1px 0 0 black, 1px 0 0 0 black, 0 1px 0 0 black; }
You can use the pseudo element :after of the table row to display above the whole tr, with pointer events: none; and apply the box-shadow on hover of the tr.
example:
.custom-table {
border-radius: 10px;
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
}
table {
margin-bottom: 0;
color: #4e4e4e;
}
thead {
background: #000000;
color: #FFFFFF;
text-transform: uppercase;
font-size: 15px;
line-height: 18px;
font-weight: 600;
}
th {
padding: 20px 40px;
}
tr:hover:after {
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.1);
transition: box-shadow 0.3s ease-in-out;
}
tbody tr {
background: #FFFFFF;
position: relative;
}
tbody tr:after {
display: block;
content: '';
width: 100%;
height: 100%;
position: absolute;
z-index: 2;
pointer-events: none;
top: 0;
left: 0;
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0);
transition: box-shadow 0.3s ease-in-out;
}
td {
padding: 17px 40px;
border: 0;
vertical-align: middle;
}
<div class="custom-table table-responsive">
<table class="table">
<thead class="table-header">
<tr class="table-row">
<th scope="col" class="table-col">Date & Time</th>
<th scope="col" class="table-col">Meeting Name</th>
<th scope="col" class="table-col">Document</th>
<th scope="col" class="table-col">Type of Meeting</th>
</tr>
</thead>
<tbody class="table-body">
<tr class="table-row">
<td class="table-col"><span class="meeting-date">16 Nov 2021 <b>Saturday</b></span><span class="meeting-time">7:00 PM</span></td>
<td class="table-col">Lorem ipsum dolor sit amet</td>
<td class="table-col"><span class="member-document">quis nostrud exercitation ullamco</span></td>
<td class="table-col"><span class="meeting-type type-1">MEETINGS</span></td>
</tr>
<tr class="table-row">
<td class="table-col"><span class="meeting-date">16 Nov 2021 <b>Saturday</b></span><span class="meeting-time">7:00 PM</span></td>
<td class="table-col">Lorem ipsum dolor sit amet</td>
<td class="table-col"><span class="member-document">quis nostrud exercitation ullamco</span></td>
<td class="table-col"><span class="meeting-type type-1">MEETINGS</span></td>
</tr>
<tr class="table-row">
<td class="table-col"><span class="meeting-date">16 Nov 2021 <b>Saturday</b></span><span class="meeting-time">7:00 PM</span></td>
<td class="table-col">Lorem ipsum dolor sit amet</td>
<td class="table-col"><span class="member-document">quis nostrud exercitation ullamco</span></td>
<td class="table-col"><span class="meeting-type type-1">MEETINGS</span></td>
</tr>
</tbody>
</table>
</div>
This could be done with the ::before or ::after pseudo-element
HTML - If you have a table like this
<table>
<thead>
<tr>
<th>S/N</th>
<th>Name</th>
<th>Age</th>
<th>Pet Choice</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
<td>Emeka Orji</td>
<td>200</td>
<td>Cat</td>
</tr>
<tr>
<td>2</td>
<td>Enoch Orji</td>
<td>12</td>
<td>Dog</td>
</tr>
<tr>
<td>3</td>
<td>Favour Orji</td>
<td>17</td>
<td>Monkey</td>
</tr>
</tbody>
</table>
CSS - You can add a shadow to a table cell like this
table {
border-collapse: collapse;
}
table td, table th {
position: relative;
padding: .5em;
}
tr td:first-of-type::before, tr th:first-of-type::before {
content: '';
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #6060bf;
z-index: -1;
box-shadow: 7px 1px 6px 0px #0006;
}
But the downside of this is that you may run into a few problems when trying to select and alter the value of the ::before or ::after pseudo-element with javascript. So the best solution I have to this is:
You could put a span element inside the table cell you want to style like this:
HTML
<table>
<thead>
<tr>
<th>S/N <span class="shadow"></span></th>
<th>Name</th>
<th>Age</th>
<th>Pet Choice</th>
</tr>
</thead>
<tbody>
<tr>
<td>1 <span class="shadow"></span></td>
<td>Emeka Orji</td>
<td>200</td>
<td>Cat</td>
</tr>
<tr>
<td>2 <span class="shadow"></span></td>
<td>Enoch Orji</td>
<td>12</td>
<td>Dog</td>
</tr>
<tr>
<td>3 <span class="shadow"></span></td>
<td>Favour Orji</td>
<td>17</td>
<td>Monkey</td>
</tr>
</tbody>
</table>
And in your CSS style the shadow element with the same styles you as before, like so:
table {
border-collapse: collapse;
}
table td, table th {
position: relative;
padding: .5em;
}
.shadow {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: #6060bf;
z-index: -1;
box-shadow: 7px 1px 6px 0px #0006;
}
This way you would be able to select the span element in your javascript like this:
const cellShadow = document.querySelector('td .shadow');
Check out this pen below. Full code demo there.
https://codepen.io/emekaorji/pen/QWQzBeM
in react, i have combined the answer as below. It worked fine in chrome, >firefox, ie11
.select_row{
color: #43B149;
font-weight: bolder !important;
background: #e4e5e6 !important;
box-shadow: 1px 0px 1px 0px #cad6ce !important;
-moz-box-shadow:1px 0px 1px 0px #cad6ce !important;
-webkit-box-shadow:1px 0px 1px 0px #cad6ce !important;
transform: scale(1);
-webkit-transform: scale(1);
-moz-transform: scale(1);
-ms-transform: scale(1);
td{box-shadow: 0px 3px 0px 0px #cad6ce !important;
-moz-box-shadow:0px 3px 0px 0px #cad6ce !important;
-webkit-box-shadow:0px 3px 0px 0px #cad6ce !important;
background: #e4e5e6 !important;
}
}
.table-forecast{
border-collapse: separate;
border-spacing: 0px;
}
Related
I have a table on which I want to highlight a number of successive rows (TR's) by applying a box-shadow around them.
My strategy was to apply a class called "selected-top" to the first row of the selection, classes "selected-middle" for the middle part, and "selected-bottom" for the last row.
However, the shadows of the middle rows bleed over. I tried to rectify this by using z-index (I know that I have to add a relative property with that, so I did), but they seem to have no effect:
Here's the code:
tr.selected-top {
box-shadow: -5px -5px 5px #000, 5px -5px 5px #000;
position: relative;
z-index:10;
}
tr.selected-middle {
box-shadow: -5px 0px 5px #000, 5px 0px 5px #000;
position: relative;
z-index: -1;
}
The table is just a regular table:
<table>
<tr><td>stuff</td></tr>
<tr class="selected-top"><td>highlighting starts</td></tr>
<tr class="selected-middle"><td>highlighting middle</td></tr>
<tr class="selected-bottom"><td>highlighting end</td></tr>
<tr><td>other stuff</td></tr>
</table>
What am I doing wrong?
By the way, I did try to only apply a shadow to only the sides for the middle rows, but that way the shadow is not continuous.
Update: #Aditya Toke, like so: (left is wrong shading, right is correct shading)
You can achieve it using ::before and ::after pseudo elements to mask the top and bottom shadow from "middle" row.
The height of the pseudo elements is set exactly equal to the length of the shadow for masking and is absolute position.
Since the shadow hides the top borders of selected-bottom and it's next sibling element we need to add them back as:
tr.selected-middle td,
tr.selected-bottom td {
border-bottom: 1px solid #666;
}
body {
background-color: #1b1b1b;
margin: 20px;
}
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: auto;
box-sizing: border-box;
border: none;
margin: auto;
}
tr { display: block; }
tr, td {
height: 50px;
background: #333;
color: #eee;
}
td {
padding-left: 16px;
min-width: 170px;
width: 100%;
border-top: 1px solid #666;
}
tr.selected-top {
position: relative;
box-shadow: -5px -5px 5px #000, 5px -5px 5px #000;
}
tr.selected-middle {
position: relative;
box-shadow: 0px 0px 5px 5px #000;
}
tr.selected-bottom {
position: relative;
box-shadow: 5px 5px 5px #000, -5px 5px 5px #000;
}
tr.selected-middle ::before,
tr.selected-middle ::after {
pointer-events: none;
position: absolute;
content:" ";
background-color: #333;
left: 0;
width: 100%;
}
tr.selected-middle ::before {
height: 10px;
top: -10px;
}
tr.selected-middle ::after {
top: calc(100% + 4px);
height: 5px;
}
tr.selected-middle td,
tr.selected-bottom td {
border-bottom: 1px solid #666;
}
<table>
<tbody>
<tr>
<td>Some stuffs</td>
</tr>
<tr class="selected-top">
<td>highlighting starts</td>
</tr>
<tr class="selected-middle">
<td>highlighting middle</td>
</tr>
<tr class="selected-bottom">
<td>highlighting ends</td>
</tr>
<tr>
<td>Some stuffs</td>
</tr>
</tbody>
</table>
table {
height: 67vh;
width: 59vw;
background-color: #333333;
}
td {
/* background-color: #333333; */
color: white;
}
div {
display: flex;
justify-content: center;
align-items: center;
}
.div1 {
box-shadow: -5px -5px 5px #000, 5px -5px 5px #000;
height: 100%;
border: 1px solid darkgrey;
border-left: 0;
border-right: 0;
}
.div2 {
box-shadow: -4px 0px 2px 0.5px #000, 2px 0px 0.5px 0.5px #000, 5px 0.5px 3px 0px #000;
height: 100%;
border: 1px solid #333333;
}
.div3 {
box-shadow: -6px 3px 5px #000, 6px 5px 6px 1px #000;
height: 100%;
position: relative;
border: 1px solid darkgrey;
border-left: 0;
border-right: 0;
}
<!DOCTYPE html>
<html lang="en">
<body>
<table>
<tr>
<td>stuff</td>
</tr>
<tr class="selected-top">
<td>
<div class="div1">
highlighting starts
</div>
</td>
</tr>
<tr class="selected-middle">
<td>
<div class="div2">
highlighting middle
</div>
</td>
</tr>
<tr class="selected-bottom">
<td>
<div class="div3">
highlighting end
</div>
</td>
</tr>
<tr>
<td>other stuff</td>
</tr>
</table>
</body>
</html>
I tried to create similar to what you have provided in the expected output
I have a table. I want that when user mouse up a row, the selected row is having this:
.list-orders tr:hover {
border-top: 1px solid #f2f2f2;
border-bottom: 2px solid #cccccc;
}
However, when those borders are getting applied, the whole table and its rows is like getting blink up and down.
I want to achieve something like Gmail hover effect.
How can I fix this?
If you want the same as Gmail you can use box-shadow instead of applying borders to the tr element.
.list-orders tr:hover {
box-shadow: 0 0 0 1px #000000;
}
<table class="list-orders">
<tr>
<td>a1</td>
<td>b1</td>
</tr>
<tr>
<td>a2</td>
<td>b2</td>
</tr>
<tr>
<td>a3</td>
<td>b3</td>
</tr>
</table>
Box Shadow
Easier to use box-shadow:
tr:hover
{
box-shadow: inset 1px 0 0 #dadce0, inset -1px 0 0 #dadce0,
0 1px 2px 0 rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15); */
}
Helper: https://www.cssmatic.com/box-shadow
tr td{
cursor: pointer;
}
tr:hover
{
box-shadow: inset 1px 0 0 #dadce0, inset -1px 0 0 #dadce0,
0 1px 2px 0 rgba(60,64,67,.3), 0 1px 3px 1px rgba(60,64,67,.15); */
}
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
</tr>
</table>
Borders
By borders - less flexible (Buggy when you set diff bottom/top borders).
Set before (Transparent + width) & Hover (change color + width)
tr {
border-bottom: 1px solid transparent;
border-top: 1px solid transparent;
}
tr:hover td {
border-bottom: 1px solid #000000;
border-top: 1px solid #000000;
}
table {
border-collapse: collapse;
}
tr td{
cursor: pointer;
}
tr {
border-top: 1px solid transparent;
border-bottom: 1px solid transparent;
}
tr:hover td {
border-top: 1px solid red;
border-bottom: 1px solid red;
}
<table style="width:100%">
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>Jill</td>
<td>Smith</td>
</tr>
<tr>
<td>Eve</td>
<td>Jackson</td>
</tr>
</table>
When I add td element with a dark background in my table that has a light background with a border, I want that in the dark td element, the border of the table doesn't see.
For example:
table {
border: 1px solid yellow;
width: 40%;
border-spacing: 0;
}
td {
padding: 10px;
}
td.black {
background: #000;
color: #fff;
}
<table>
<tr>
<td class="black">Something</td>
</tr>
<tr>
<td>Something else</td>
</tr>
</table>
In the first td, the dark td, I don't want to see the yellow border of the table.
You can't, but you could just add the border to the default 'td' element insted of 'table' and create a special rule for the black one.
table {
width: 40%;
border-spacing: 0;
/* border-collapse: collapse; // get a single border */
}
td {
padding: 10px;
border: 2px solid yellow;
}
td.black {
background: #000;
color: #fff;
border: 2px solid green;
}
http://jsfiddle.net/pr1d3c5b/
If you want to add just a box-shadow, you can try with this variation (for red color), but it's not precise
-webkit-box-shadow: 0px 0px 0px 2px rgba(255, 0, 0, 1);
-moz-box-shadow: 0px 0px 0px 2px rgba(255, 0, 0, 1);
box-shadow: 0px 0px 0px 2px rgba(255, 0, 0, 1);
http://jsfiddle.net/pr1d3c5b/1/
You can try this generator http://css3gen.com/box-shadow/ and play with the 'spread' value under the optional settings
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;
}
Does anyone know how to style tr as we like?
I've used border-collapse on table, after that tr's can display 1px solid border I give them.
However, when I've tried -moz-border-radius, it doesn't work. Even simple margin doesn't work.
You can only apply border-radius to td, not tr or table. I've gotten around this for rounded corner tables by using these styles:
table {
border-collapse: separate;
border-spacing: 0;
}
td {
border: solid 1px #000;
border-style: none solid solid none;
padding: 10px;
}
tr:first-child td:first-child { border-top-left-radius: 10px; }
tr:first-child td:last-child { border-top-right-radius: 10px; }
tr:last-child td:first-child { border-bottom-left-radius: 10px; }
tr:last-child td:last-child { border-bottom-right-radius: 10px; }
tr:first-child td { border-top-style: solid; }
tr td:first-child { border-left-style: solid; }
<table>
<tr>
<td>1.1</td>
<td>1.2</td>
<td>1.3</td>
</tr>
<tr>
<td>2.1</td>
<td>2.2</td>
<td>2.3</td>
</tr>
<tr>
<td>3.1</td>
<td>3.2</td>
<td>3.3</td>
</tr>
</table>
Be sure to provide all the vendor prefixes. You can see it in action on JSFiddle too.
Actual Spacing Between Rows
This is an old thread, but I noticed reading the comments from the OP on other answers that the original goal was apparently to have border-radius on the rows, and gaps between the rows. It does not appear that the current solutions exactly do that. theazureshadow's answer is headed in the right direction, but seems to need a bit more.
For those interested in such, here is a fiddle that does separate the rows and applies the radius to each row. (NOTE: Firefox currently has a bug in displaying/clipping background-color at the border radii.)
The code is as follows (and as theazureshadow noted, for earlier browser support, the various vendor prefixes for border-radius need added).
table {
border-collapse: separate;
border-spacing: 0 10px;
margin-top: -10px; /* correct offset on first border spacing if desired */
}
td {
border: solid 1px #000;
border-style: solid none;
padding: 10px;
background-color: cyan;
}
td:first-child {
border-left-style: solid;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
td:last-child {
border-right-style: solid;
border-bottom-right-radius: 10px;
border-top-right-radius: 10px;
}
Bonus info: border-radius has no effect on tables with border-collapse: collapse; and border set on td's. And it doesn't matter if border-radius is set on table, tr or td—it's ignored.
http://jsfiddle.net/Exe3g/
The tr element does honor the border-radius. Can use pure html and css, no javascript.
JSFiddle link: http://jsfiddle.net/pflies/zL08hqp1/10/
tr {
border: 0;
display: block;
margin: 5px;
}
.solid {
border: 2px red solid;
border-radius: 10px;
}
.dotted {
border: 2px green dotted;
border-radius: 10px;
}
.dashed {
border: 2px blue dashed;
border-radius: 10px;
}
td {
padding: 5px;
}
<table>
<tr>
<td>01</td>
<td>02</td>
<td>03</td>
<td>04</td>
<td>05</td>
<td>06</td>
</tr>
<tr class='dotted'>
<td>07</td>
<td>08</td>
<td>09</td>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>
<tr class='solid'>
<td>13</td>
<td>14</td>
<td>15</td>
<td>16</td>
<td>17</td>
<td>18</td>
</tr>
<tr class='dotted'>
<td>19</td>
<td>20</td>
<td>21</td>
<td>22</td>
<td>23</td>
<td>24</td>
</tr>
<tr class='dashed'>
<td>25</td>
<td>26</td>
<td>27</td>
<td>28</td>
<td>29</td>
<td>30</td>
</tr>
</table>
According to Opera the CSS3 standard does not define the use of border-radius on TDs. My experience is that Firefox and Chrome support it but Opera does not (don't know about IE). The workaround is to wrap the td content in a div and then apply the border-radius to the div.
All the answers are way too long. The easiest way to add border radius to a table element that accepts border as a property, is doing border radius with overflow: hidden.
border: xStyle xColor xSize;
border-collapse: collapse;
border-radius: 1em;
overflow: hidden;
I think collapsing your borders is the wrong thing to do in this case. Collapsing them basically means that the border between two neighboring cells becomes shared. This means it's unclear as to which direction it should curve given a radius.
Instead, you can give a border radius to the two lefthand corners of the first TD and the two righthand corners of the last one. You can use first-child and last-child selectors as suggested by theazureshadow, but these may be poorly supported by older versions of IE. It might be easier to just define classes, such as .first-column and .last-column to serve this purpose.
Not trying to take any credits here, all credit goes to #theazureshadow for his reply, but I personally had to adapt it for a table that has some <th> instead of <td> for it's first row's cells.
I'm just posting the modified version here in case some of you want to use #theazureshadow's solution, but like me, have some <th> in the first <tr>. The class "reportTable" only have to be applied to the table itself.:
table.reportTable {
border-collapse: separate;
border-spacing: 0;
}
table.reportTable td {
border: solid gray 1px;
border-style: solid none none solid;
padding: 10px;
}
table.reportTable td:last-child {
border-right: solid gray 1px;
}
table.reportTable tr:last-child td{
border-bottom: solid gray 1px;
}
table.reportTable th{
border: solid gray 1px;
border-style: solid none none solid;
padding: 10px;
}
table.reportTable th:last-child{
border-right: solid gray 1px;
border-top-right-radius: 10px;
}
table.reportTable th:first-child{
border-top-left-radius: 10px;
}
table.reportTable tr:last-child td:first-child{
border-bottom-left-radius: 10px;
}
table.reportTable tr:last-child td:last-child{
border-bottom-right-radius: 10px;
}
Feel free to adjust the paddings, radiuses, etc to fit your needs. Hope that helps people!
CSS:
tr:first-child th:first-child {
border-top-left-radius: 70px;
border-bottom-left-radius: 70px;
}
tr:first-child th:last-child {
border-top-right-radius: 70px;
border-bottom-right-radius: 70px;
}
You can also use outline:
table {
border-radius: 10px;
outline: 1px solid gray;
}
I found that adding border-radius to tables, trs, and tds does not seem to work 100% in the latest versions of Chrome, FF, and IE. What I do instead is, I wrap the table with a div and put the border-radius on it.
<div class="tableWrapper">
<table>
<tr><td>Content</td></tr>
<table>
</div>
.tableWrapper {
border-radius: 4px;
overflow: hidden;
}
If your table is not width: 100%, you can make your wrapper float: left, just remember to clear it.
Or use box-shadow if table have collapse
Use border-collapse:seperate; and border-spacing:0; but only use border-right and border-bottom for the tds, with border-top applied to th and border-left applied to only tr td:nth-child(1).
You can then apply border radius to the corner tds (using nth-child to find them)
https://jsfiddle.net/j4wm1f29/
<table>
<tr>
<th>title 1</th>
<th>title 2</th>
<th>title 3</th>
</tr>
<tr>
<td>item 1</td>
<td>item 2</td>
<td>item 3</td>
</tr>
<tr>
<td>item 1</td>
<td>item 2</td>
<td>item 3</td>
</tr>
<tr>
<td>item 1</td>
<td>item 2</td>
<td>item 3</td>
</tr>
<tr>
<td>item 1</td>
<td>item 2</td>
<td>item 3</td>
</tr>
</table>
table {
border-collapse: seperate;
border-spacing: 0;
}
tr th,
tr td {
padding: 20px;
border-right: 1px solid #000;
border-bottom: 1px solid #000;
}
tr th {
border-top: 1px solid #000;
}
tr td:nth-child(1),
tr th:nth-child(1) {
border-left: 1px solid #000;
}
/* border radius */
tr th:nth-child(1) {
border-radius: 10px 0 0 0;
}
tr th:nth-last-child(1) {
border-radius: 0 10px 0 0;
}
tr:nth-last-child(1) td:nth-child(1) {
border-radius: 0 0 0 10px;
}
tr:nth-last-child(1) td:nth-last-child(1) {
border-radius: 0 0 10px 0;
}
Here's an example that puts a border with radius on a single row:
table { border-collapse: separate; border-spacing: 0; }
td { padding: 5px; }
.rowBorderStart {
border: 1px solid #000;
border-right: 0px;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
.rowBorderMiddle {
border: 1px solid #000;
border-left: 0px;
border-right: 0px;
}
.rowBorderEnd {
border: 1px solid #000;
border-left: 0px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
<table>
<tr><td>1.1</td><td>1.2</td><td>1.3</td></tr>
<tr><td class='rowBorderStart'>2.1</td><td class='rowBorderMiddle'>2.2</td><td class='rowBorderEnd'>2.3</td></tr>
<tr><td>3.1</td><td>3.2</td><td>3.3</td></tr>
</table>
According to #Craigo answer, I make some minor change, take a look:)
table {
border-collapse: separate;
border-spacing: 0 16px;
}
tr td {
border: 1px solid transparent;
transition: all ease 0.3s;
padding: 5px;
}
tr td:first-child {
border-right: 0px;
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
tr td:last-child {
border-left: 0px;
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
tr td:not(:first-child, :last-child) {
border-left: 0px;
border-right: 0px;
}
tr:hover td:first-child {
border-color: black;
border-right: 0px;
}
tr:hover td:last-child {
border-color: black;
border-left: 0px;
}
tr:hover td:not(:first-child, :last-child) {
border-color: black;
border-left: 0px;
border-right: 0px;
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>How to add border radius on table row</title>
</head>
<body>
<table>
<tbody>
<tr>
<td>01</td>
<td>02</td>
<td>03</td>
<td>04</td>
<td>05</td>
<td>06</td>
</tr>
<tr>
<td>07</td>
<td>08</td>
<td>09</td>
<td>10</td>
<td>11</td>
<td>12</td>
</tr>
</tbody>
</table>
</body>
</html>
Use the below code to round the corners of the table:
thead th:first-child{border-top-right-radius: 15px;}
thead th:last-child{border-top-left-radius: 15px;}
tbody tr:last-child>td:first-child{border-bottom-right-radius: 15px;}
tbody tr:last-child>td:last-child{border-bottom-left-radius: 15px;}
I would Suggest you use .less instead,
change your .css file to .less and use the following code:
table {
border-collapse: separate;
border-spacing: 0;
}
td {
border: solid 1px #000;
border-style: none solid solid none;
padding: 10px;
}
tr td:first-child {
border-top-left-radius: 10px;
border-bottom-left-radius: 10px;
}
tr td:last-child {
border-top-right-radius: 10px;
border-bottom-right-radius: 10px;
}
tr td {
border-top-style: solid;
}
tr td:first-child {
border-left-style: solid;
}
tr{
cursor: pointer;
}
tr:hover{
td{
background-color: red;
}
}