看到我相关但又不同的问题:css box-shadow for table row?
这是我的HTML代码:
<style>
.yellow{
background-color: yellow;
}
td{
width:40px;
}
tr:first-child {
box-shadow: inset 1px 1px 5px 5px #d99292;
}
</style>
<table>
<tr>
<td class=yellow>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td class=yellow>4</td>
</tr>
</table>
我的问题是:如何在单元格1的背景顶部显示插入的放映节目?
答案 0 :(得分:2)
使用可以在阴影后面创建的伪元素为表格单元格上色:
table {
position:relative;
z-index:-1;
}
.yellow {
position:relative;
}
.yellow::before {
content:"";
position:absolute;
z-index:-1;
top:0;
left:0;
right:0;
bottom:0;
background:yellow;
}
td {
width: 40px;
}
tr:first-child {
box-shadow: inset 1px 1px 5px 5px #d99292;
}
<table>
<tr>
<td class=yellow>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td class=yellow>4</td>
</tr>
</table>
答案 1 :(得分:2)
您也可以尝试mix-blend-mode
mix-blend-mode
CSS属性设置元素的内容应如何与元素的父级内容和元素的背景融合。
.yellow{
background-color: yellow;
mix-blend-mode:multiply
}
td{
width:40px;
}
tr:first-child {
box-shadow: inset 1px 1px 5px 5px #d99292;
/*optionnal :
background:white ;
to avoid .yellow mixing eventually with body, or else background */
}
<table>
<tr>
<td class=yellow>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td class=yellow>4</td>
</tr>
</table>
答案 2 :(得分:1)
我在这里工作。
在顶部添加一个绝对空白tr
。
.yellow{
background-color: yellow;
}
td{
width:40px;
}
tr:first-child {
position: absolute;
box-shadow: inset 1px 1px 5px 5px #d99292;
}
<table>
<tr>
<td> </td>
<td></td>
</tr>
<tr>
<td class=yellow>1</td>
<td>2</td>
</tr>
<tr>
<td>3</td>
<td class=yellow>4</td>
</tr>
</table>