【问题标题】:Box-shadow for table header in ChromeChrome中表格标题的框阴影
【发布时间】:2015-08-04 21:54:19
【问题描述】:

我正在尝试将 box-shadow 添加到表格的第一行(标题), 在 Firefox 中运行良好,但在 Chrome 中无法运行。

我尝试过使用不同的显示属性值(例如“显示:块”), 这会在 Chrome 中添加阴影,但会将整个标题移动到第一列的第一个单元格中。关于如何在我的情况下添加 box-shadow 的任何解决方案?

下面是我的 CSS/HTML 示例(box-shadow 与选择器“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>

【问题讨论】:

标签: html css


【解决方案1】:

将你的盒子阴影效果移动到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 在您的情况下与 th 相同,因此您不需要它。

要使其在最新版本的 IE 中工作,您需要添加: 边框折叠:分离;

【讨论】:

  • 您的回答完全破坏了除 chrome 之外的所有浏览器的设计... ;)
【解决方案2】:

Chrome 通常在连续使用 box-shadow 方面存在问题。只需将您的“tr:firstchild”重写为“th”元素,它就可以在 Chrome 中使用。 “box-shadow 属性仅适用于具有 display: block 或 display:inline-block 属性的元素。”

因此,如果您使用 display: block 或 display: inline-block ,它会应用您的阴影,但也会破坏表格的完整布局。所以我建议你重建你的影子... :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-08
    • 2023-03-30
    • 2012-10-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-25
    相关资源
    最近更新 更多