简体   繁体   English

Hover 超过另一个 div 时

[英]Hover over another div when it comes to

when I hover over "Div2", I want the hover of "Div1" to work当我 hover 超过“Div2”时,我希望“Div1”的 hover 工作

 .Div1:hover{ background:red; }
 <div class="Div1">Hello!</div> <div class="Div2">Open hello!</div>

You can choose one class for both to make hoover works for both.您可以为两者选择一个 class 以使吸尘器对两者都有效。

 .DivHoover:hover{ background:red; }
 <div class="Div1 DivHoover">Hello!</div> <div class="Div1 DivHoover">Open hello!</div>

You can use display: flex on the container, then change the rendering order.您可以在容器上使用 display: flex,然后更改渲染顺序。 Then you can hover on div2 and highlight div1.然后你可以在 div2 上 hover 并突出显示 div1。

.container {
  display: flex;
  flex-wrap: wrap;
}

.div1, .div2 {
  flex: 0 0 100%;
}

.div1 { order: 1; }
.div2 { order: 2; }

.div2:hover ~ .div1 {
  background-color: red;
}
<div class="container">
  <div class="div2">hello!</div>
  <div class="div1">open hello!</div>
</div>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM