css insert box-shadow pour la ligne de table?

Oct 24 2020

voir ma question connexe mais différente: css box-shadow pour la ligne du tableau?

Voici mon code 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>
Le but est d'avoir une ombre portée incrustée dans la première ligne. Le problème est que la couleur d'arrière-plan de la cellule 1 l'obscurcit.

Ma question est la suivante: comment puis-je faire apparaître le diaporama en incrustation sur l'arrière-plan de la cellule 1?

Réponses

2 G-Cyrillus Oct 24 2020 at 20:25

Vous pouvez également essayer mix-blend-mode

La mix-blend-modepropriété CSS définit la manière dont le contenu d'un élément doit se fondre avec le contenu du parent de l'élément et l'arrière-plan de l'élément.

.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 TemaniAfif Oct 24 2020 at 17:00

coloriez la cellule du tableau à l'aide d'un pseudo élément que vous pouvez créer derrière l'ombre:

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 huanfeng Oct 24 2020 at 14:27

J'ai un travail ici.

Ajout d'un vide absolu trpour être au top.

.yellow{
    background-color: yellow;
}
td{
    width:40px;
}
tr:first-child {
    position: absolute;
    box-shadow: inset 1px 1px 5px 5px #d99292;
}
<table>
  <tr>
    <td>&nbsp;</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>