简体   繁体   English

更改 hover css 上的相邻元素

[英]Changing adjacent elements on hover css

Please tell me why when you hover over the third div , the size of the second div does not change, as when you hover over the first div .请告诉我为什么当你 hover 超过第三个div时,第二个div的大小不会改变,就像你在第一个div上的 hover 一样。

 #block { width: 50%; white-space: nowrap; }.div { display: inline-block; text-align: center; } div:nth-child(1) { width: 10%; background: red; } div:nth-child(2) { width: 80%; background: blue; } div:nth-child(3) { width: 10%; background: green; } div:nth-child(1):hover { width: 80%; } div:nth-child(1):hover + div:nth-child(2) { width: 10%; } div:nth-child(3):hover { width: 80%; } div:nth-child(3):hover + div:nth-child(2) { width: 10%; }
 <div id="block"> <div class="div">1</div> <div class="div">2</div> <div class="div">3</div> </div>

Quoting from Mozilla Developers Website For More info Check the link at the bottom引用自 Mozilla 开发者网站了解更多信息请查看底部的链接

The adjacent sibling combinator (+) separates two selectors and matches the second element only if it immediately follows the first element, and both are children of the same parent element.相邻的兄弟组合符 (+) 分隔两个选择器,并且仅当它紧跟在第一个元素之后,并且它们都是同一个父元素的子元素时才匹配第二个元素。

This means it will try to find a sibling of the same parent that is after the current selecting element not the sibling before the current One.这意味着它将尝试查找当前选择元素之后的同一父级的兄弟姐妹,而不是当前 One 之前的兄弟姐妹。

https://developer.mozilla.org/en-US/docs/Web/CSS/Adjacent_sibling_combinator https://developer.mozilla.org/en-US/docs/Web/CSS/Adjacent_sibling_combinator

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

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