我试图通过悬停在锚标签上来改变div颜色但是当我没有发生任何事情时,这里是我的代码,jsfiddel链接https://jsfiddle.net/rhulkashyap/udvzanqz/.
HTML和CSS
.hover-me{
margin-bottom:50px;
display:block;
}
.change{
width:200px;
height:200px;
background:#00ACC1;
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
font-size:20px;
color:#fff;
}
.hover-me:hover .change{
background:#00796B;
}
Change Div color by hovering me
Hello Universe
你需要使用 sibling selector
.hover-me{
margin-bottom:50px;
display:block;
}
.change{
width:200px;
height:200px;
background:#00ACC1;
display: flex;
align-items: center;
flex-direction: column;
justify-content: center;
font-size:20px;
color:#fff;
}
.hover-me:hover ~ .change{
background:#00796B;
}
Change Div color by hovering me
Hello Universe