0

i'm experimenting with var in css and i found a bug(?). Hover works only on first div. Could someone help me with this issue? Thank you in advance

body {
  background-color: aqua;
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1%;
}

.box {
  box-sizing: border-box;
  width: 100%;
  position: relative;
  transform-style: preserve-3d;
  transform: rotate(calc(var(--abc)* 10deg));
  background-color: rgba(150, 250, 0, calc(var(--abc)* 0.1));
  z-index: calc(var(--abc)*-1);
  flex-shrink: 1;
  aspect-ratio: 1;
}

.box:hover {
  background-color: rgba(150, 250, 0, 1);
}
<div class="box" style="--abc:0;"></div>
<div class="box" style="--abc:1;"></div>
<div class="box" style="--abc:2;"></div>
<div class="box" style="--abc:3;"></div>
<div class="box" style="--abc:4;"></div>
<div class="box" style="--abc:5;"></div>
<div class="box" style="--abc:6;"></div>
<div class="box" style="--abc:7;"></div>
<div class="box" style="--abc:8;"></div>
<div class="box" style="--abc:9;"></div>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
Hubert
  • 9
  • 2

2 Answers2

0

Problem is combine hover and negative z-index. Use:

z-index: calc(100 + var(--abc)*-1);

Robert Máslo
  • 208
  • 2
  • 5
-1

You need to delete z-index: calc(var(--abc)*-1);

Try this:

 body{
background-color: aqua;
width: 100%;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
gap: 1%;
}

.box{
box-sizing: border-box;
width: 100%; 
position: relative;
transform-style: preserve-3d;
transform: rotate(calc(var(--abc)* 10deg));
background-color: rgba(150, 250, 0, calc(var(--abc)* 0.1));
flex-shrink: 1;
aspect-ratio: 1;
}
.box:hover {
background-color: rgba(150, 250, 0, 1);
}