I am trying to recreate this material design table I made in a Photoshop mockup:
I’ve got everything I want except for a drop shadow. When I apply a drop shadow to the tbody element, it shows in Firefox, but not Chrome or Edge.If I apply a “display: block” style to it as well, it will show. However, this removes the default “display: table-row-group” style, effectively ruining the structure of the table. How can I add a drop shadow without affecting the rest of the layout?
* {
font-family: Roboto, Arial;
}
body {
background: #f8f8f8;
}
table {
border-collapse: collapse;
width: 100%;
}
th {
font-weight: normal;
opacity: .7;
text-align: left;
padding-left: 20px;
padding-bottom: 10px;
}
td {
padding: 20px;
}
tbody tr:nth-child(even) {
background: rgba(128,128,128,.05);
}
tbody {
background: #fff;
/* This doesn't work unless "display: block" is applied, which ruins the structure */
box-shadow: 0 2px 5px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12);
-moz-box-shadow: 0 2px 5px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12);
-webkit-box-shadow: 0 2px 5px 0 rgba(0,0,0,0.16),0 2px 10px 0 rgba(0,0,0,0.12);
}
.grey {
opacity: .5;
}
.green {
color: #4caf50;
}
<table>
<thead>
<tr>
<th>Name</th>
<th>Date</th>
<th>Grade</th>
</tr>
</thead>
<tbody>
<tr>
<td>You</td>
<td>Today, 4:12 PM</td>
<td class="green">92%</td>
</tr>
<tr>
<td>John Smith</td>
<td>Today, 3:28 PM</td>
<td class="grey">Hidden</td>
</tr>
<tr>
<td>Bobby Newport</td>
<td>Yesterday</td>
<td class="grey">Hidden</td>
</tr>
<tr>
<td>Jim Halpert</td>
<td>2 days ago</td>
<td class="grey">Hidden</td>
</tr>
<tr>
<td>Detlow Coffin</td>
<td>2 days ago</td>
<td class="grey">Hidden</td>
</tr>
</tbody>
</table>
2
Answers
Add a property of
or
to tbody and see what happens.
You can also try :before and :after.
I spent a few hours on this issue and have finally a working solution that doesn’t break the table layout. But now that I think about it flexbox would probably be much simpler…
Here is the fiddle: https://jsfiddle.net/jitowix/o2gx7sc4/