热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

CSS-连接多个:悬停在不同的部分-CSS-Connectingmultiple:hoverwithdifferentsection

Ineedlittlehelpwith:hoveronmultipleobjectswithdifferentcolors.WhenIhoveronthefirst

I need little help with :hover on multiple objects with different colors. When I hover on the first section, the second one should change the color too.

我需要一些帮助:将鼠标悬停在具有不同颜色的多个对象上。当我将鼠标悬停在第一部分时,第二部分也应该改变颜色。

HTML

CSS

.object1 {
background-color:#F00;
width:100px;
height:50px;
}


.object2 {
background-color:#00F;
width:100px;
height:50px;
}

.object1:hover{
    background-color:#FF0;
    }

.object2:hover {
    background-color:#000;

}

Thanks for reading :)

谢谢阅读 :)

1 个解决方案

#1


2  

You can use CSS's Adjacent Sibling Combinator + selector to apply changes to .object2 when hovering over .object1, but you cannot do this in reverse:

当鼠标悬停在.object1上时,您可以使用CSS的Adjacent Sibling Combinator +选择器将更改应用于.object2,但您无法反向执行此操作:

.object1:hover,
.object1:hover + .object2 {
    background-color:#FF0;
}

Demo

.object1 {
  background-color:#F00;
  width:100px;
  height:50px;
}


.object2 {
  background-color:#00F;
  width:100px;
  height:50px;
}

.object1:hover,
.object1:hover + .object2 {
    background-color:#FF0;
}

.object2:hover {
    background-color:#000;

}
Section 1
Section 2


推荐阅读
author-avatar
spring709272032
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有