CSS inserto box-shadow per la riga della tabella?

Oct 24 2020

vedi la mia domanda correlata ma diversa: css box-shadow per la riga della tabella?

Ecco il mio codice 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>
L'obiettivo è avere un'ombra esterna inserita nella prima riga. Il problema è che il colore di sfondo della cella 1 lo oscura.

La mia domanda è: come faccio a mostrare il drop show inserito sopra lo sfondo della cella 1?

Risposte

2 G-Cyrillus Oct 24 2020 at 20:25

Puoi anche provare mix-blend-mode

La mix-blend-modeproprietà CSS imposta il modo in cui il contenuto di un elemento deve fondersi con il contenuto del genitore dell'elemento e dello sfondo dell'elemento.

.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

colora la cella della tabella usando uno pseudo elemento che puoi creare dietro l'ombra:

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

Ho un lavoro qui intorno.

Aggiunta di un vuoto assoluto trper essere in cima.

.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>