0

我有一个简单的表格,带有box-shadow,但我想从任何阴影中排除第一个单元格。

我已经尝试添加box-shadow: none到该单元格,但它不会覆盖整个表格上的阴影。我什至不确定这是否可能?

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;
}

这是一个显示表格示例的小提琴

这可能吗?

更新

我所说的第一个单元格是指与班级一起排的第一个单元格header-table .header td {}

这是完美结果的图像:

在此处输入图像描述

4

3 回答 3

1

您应该添加box-shadowtbody添加也可以使用它box-shadowthead您可以排除它,下面将为您提供更多信息。

	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>

于 2015-10-06T06:58:27.833 回答
0

这可以通过为该单元格提供 ID 或类属性来完成,然后将 css 应用于您对 al td 元素的喜好,然后调用第一个单元格,如 #firstCell 并不给它背景:无;颜色:黑色; 它通常是这样的。

于 2015-10-06T06:58:21.303 回答
0

这就是我想出来的,并不完美,但这个技巧足够接近预期的结果

我将第一个单元格更改为:

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

CSS:

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

在这里你可以看到它

于 2015-10-06T07:16:17.740 回答