-1

I want when hovering on yellow box which has the class named card the element which is a blue box that has a class named box to appear. I have done that in css like this

.box {
  display: none;
}

.card:hover + .box {
  display: inline-block;
  position: absolute;
  height: 30px;
  width: 40px;
  background-color: blue;
  top: 114px;
  right: 94px;
  border-radius: 0px 0px 99px 99px;
}

but it didn't work with me what is the problem ? this is the sandbox link https://codesandbox.io/s/quiet-water-yx1l3g?file=/src/styles.css:336-358[![enter image description here]1]1

Nagween Jaffer
  • 180
  • 3
  • 13

3 Answers3

1
.box {
  display: none;
 
}

.card:hover .box {
  display: inline-block;
  position: absolute;
  height: 30px;
  width: 40px;
  background-color: blue;
  top: 114px;
  right: 94px;
  border-radius: 0px 0px 99px 99px;
}
Mohammed Shahed
  • 840
  • 2
  • 15
0

In your html .box is inside .card element. You're using adjacent sibling selector (+). just use descendant selector. .card:hover .box

.card:hover .box {
  display: inline-block;
  position: absolute;
  height: 30px;
  width: 40px;
  background-color: blue;
  top: 114px;
  right: 94px;
  border-radius: 0px 0px 99px 99px;
}
Moorthy G
  • 1,441
  • 8
  • 9
0

Just remove the plus. Plus target its same sibling element. The box element is the child of the card. So it would be best if you targeted like this.

 .card:hover .box {
     display: inline-block;
     position: absolute;
     height: 30px;
     width: 40px;
     background-color: blue;
     top: 114px;
     right: 94px;
     border-radius: 0px 0px 99px 99px;
    }
Md. Rejoan
  • 31
  • 2