johe
johe

Reputation: 21

Box-shadow for table header in Chrome

I'm trying to add box-shadow to the first row of the table (header), which works fine in Firefox, but unfortunately doesn't work in Chrome.

I have tried using different display property values (e.g "display: block"), which adds the shadow in Chrome, but moves the whole header into the first cell of the first column. Any solutions on how to add box-shadow in my case?

Below is my CSS/HTML example (box-shadow is used with selector "tr:first-child"):

body,
html {
  height: 100%;
  background-color: #E0E0E0;
}
table {
  margin-left: auto;
  margin-right: auto;
  margin-top: 10px;
  margin-bottom: 25px;
  background: linear-gradient(to bottom, #E0E0E0 0%, #E1E1E1 10%, #E5E5E5 47%, #E7E7E7 100%);
  -webkit-border-radius: 10px 10px 10px 10px;
  -moz-border-radius: 10px 10px 10px 10px;
  border-radius: 10px 10px 10px 10px;
  box-sizing: border-box;
}
table,
th,
td {
  border-collapse: collapse;
}
tr:hover {
  background-color: #E0E0E0;
}
tr:first-child {
  background-color: #E0E0E0;
  -webkit-border-radius: 10px 10px 10px 10px;
  -moz-border-radius: 10px 10px 10px 10px;
  border-radius: 10px 10px 10px 10px;
  -webkit-box-shadow: 3px 5px 10px grey;
  -moz-box-shadow: 3px 5px 10px grey;
  box-shadow: 3px 5px 10px grey;
}
th {
  background-color: #404040;
  color: #FFFFFF;
}
th,
td {
  padding: 3px;
  max-width: 600px;
}
td {
  border-bottom: 1px solid #909090;
}
td.last_row {
  border-bottom: none;
}
td:first-child {
  text-align: center;
  width: 25px;
}
td:last-child {
  text-align: center;
  width: 50px;
}
#column_1 {
  -webkit-border-radius: 10px 0px 0px 10px;
  -moz-border-radius: 10px 0px 0px 10px;
  border-radius: 10px 0px 0px 10px;
}
#column_2 {
  -webkit-border-radius: 0px 10px 10px 0px;
  -moz-border-radius: 0px 10px 10px 0px;
  border-radius: 0px 10px 10px 0px;
}
.outer_col {
  border: none;
}
<body>
  <table>
    <tr>
      <th id="column_1">ID</th>
      <th id="column_2" colspan="2">DESCRIPTION</th>
    </tr>
    <tr>
      <td class="outer_col">1</td>
      <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit</td>
      <td class="outer_col"><a href="#">Link</a>
      </td>
    </tr>
    <tr>
      <td class="outer_col">2</td>
      <td>Lorem ipsum dolor sit amet, consectetur adipiscing elit</td>
      <td class="outer_col"><a href="#">Link</a>
      </td>
    </tr>
    <tr>
      <td class="outer_col">3</td>
      <td class="last_row">Lorem ipsum dolor sit amet, consectetur adipiscing elit</td>
      <td class="outer_col"><a href="#">Link</a>
      </td>
    </tr>
  </table>
</body>

Upvotes: 2

Views: 6534

Answers (2)

SophieXLove64
SophieXLove64

Reputation: 316

Chrome has issues in general to use box-shadow on a row. Just rewrite your "tr:firstchild" to the "th"-Element and it works in Chrome. "box-shadow property works only with elements, which have display: block or display:inline-block attribute."

So if you use display: block or display: inline-block it applies your shadow, but also breaks the full layout of your table. So I'd advice to just rebuild your shadow on th... :)

Upvotes: 1

Dima
Dima

Reputation: 527

Move you box-shadow effect to th:

th {
  background-color: #404040;
  color: #FFFFFF;
  -webkit-border-radius: 10px 10px 10px 10px;
  -moz-border-radius: 10px 10px 10px 10px;
  border-radius: 10px 10px 10px 10px;
  -webkit-box-shadow: 3px 5px 10px grey;
  -moz-box-shadow: 3px 5px 10px grey;
  box-shadow: 3px 5px 10px grey;
}

tr:first-child is the same as th in your case, so you don't need it.

To make it work in recent versions of IE you will need to add to th: border-collapse:separate;

Upvotes: 1

Related Questions