0

I have a simple table, with a box-shadow, but I want to exclude the very first cell from any shadow.

I've tried adding box-shadow: none to that cell but it doesn't override the shadow on the whole table. I'm not even sure if this is possible?

HTML:

<table>
    <tr class="header">
        <td></td>
        <td>hello</td>
        <td>hello</td>
        <td>hello</td>
    </tr>
    <tr>
        <td>row 1</td>
        <td>row 1</td>
        <td>row 1</td>
        <td>row 1</td>
    </tr>
    <tr>
        <td>row 2</td>
        <td>row 2</td>
        <td>row 2</td>
        <td>row 2</td>
    </tr>
    <tr class="last-row">
        <td>row 3</td>
        <td>row 3</td>
        <td>row 3</td>
        <td>row 3</td>
    </tr>
</table>     

CSS:

table {
    width: 80%;
    margin: 30px;
    box-shadow: 0 1.5px 4px rgba(0, 0, 0, 0.24), 0 1.5px 6px rgba(0, 0, 0, 0.12);
}
.header {
    height: 50px;
    vertical-align: middle;
    text-align: center;
    color: #fff;
    background: red;
}
.header td {
    border-bottom: 2px solid #ccc;
}
.header td:first-of-type {
    background: #fff;
}
.last-row td {
    border: none !important;
}
tr td:not(.header) {
    height: 60px;
    text-align: center;
    border-bottom: 1px solid #ccc;
}

Here's a fiddle to show an example of a table

Is this possible?

UPDATE

By first cell I mean first cell in row with class header - table .header td {}

This is an image of the perfect result:

enter image description here

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
StudioTime
  • 22,603
  • 38
  • 120
  • 207

3 Answers3

1

You should add box-shadow in tbody and add box-shadow in thead also to use it you can exclude that, below will clear you more.

 table {
    width: 80%;
    margin: 30px;
    overflow: hidden;padding: 5px;
    
}
.header {
    height: 50px;
    vertical-align: middle;
    text-align: center;
    color: #fff;
    background: red;
}
.header td {
    border-bottom: 2px solid #ccc;
}
.header th:first-of-type {
    background: #fff;
}
.last-row td {
    border: none !important;
}
tr td:not(.header) {
    height: 60px;
    text-align: center;
    border-bottom: 1px solid #ccc;
}
table tbody{
 box-shadow: 0 1.5px 4px rgba(0, 0, 0, 0.24), 0 1.5px 6px rgba(0, 0, 0, 0.12);
}
table thead{
 position: relative;
}
table thead:before{
    box-shadow: 3px -2px 2px rgba(0, 0, 0, 0.2);
    content: "";
    height: 109%;
    position: absolute;
    right: 0;
    top: 0;
    width: 75%;
    z-index: -1;
}
<table>
 <thead>
     <tr class="header">
         <th></th>
         <th>hello</th>
         <th>hello</th>
         <th>hello</th>
     </tr>
    </thead>
    <tbody>
     <tr>
         <td>row 1</td>
         <td>row 1</td>
         <td>row 1</td>
         <td>row 1</td>
     </tr>
     <tr>
         <td>row 2</td>
         <td>row 2</td>
         <td>row 2</td>
         <td>row 2</td>
     </tr>
     <tr class="last-row">
         <td>row 3</td>
         <td>row 3</td>
         <td>row 3</td>
         <td>row 3</td>
     </tr>
    </tbody>    
</table>
Mukul Kant
  • 7,074
  • 5
  • 38
  • 53
0

This could be done by giving that cell either an ID or class attribute, then apply css to your liking to al td elements, then call the first cell, like #firstCell and give it no background:none; color:black; the way it normally is.

Derk
  • 42
  • 8
0

This is what I figured out, not perfect but does the trick close enough to desired result

I changed first cell to:

<td style="position: relative"><div class="overflow"></div></td>

CSS:

.overflow{
    position: absolute;
    background: #fff;
    bottom: 0;
    right: 0;
    width: 105%;
    height: 105%;
}

You can see it here

StudioTime
  • 22,603
  • 38
  • 120
  • 207