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-shadow追加して、それを使用するためにもtbody追加する必要があります。それを除外できます。以下でさらに明確になります。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 をすべての td 要素に適用し、#firstCell のように最初のセルを呼び出して、background:none; を指定しないことで実行できます。色: 黒; 通常の方法です。

于 2015-10-06T06:58:21.303 に答える