
要在一个元素悬停时影响其他元素,一个元素应该位于另一个元素内,即父子元素或同级元素。将鼠标光标放在一个元素上时,另一个元素的属性应该发生变化,即悬停效果可见。
当一个元素悬停时更改另一个元素的颜色
示例
在此示例中,我们将在鼠标悬停时更改 div 内两个框的颜色 -
Change the color
Keep the mouse cursor inside the orange colored div to change the color of the two blue boxes.
In the divBox1
Box2
当 div 悬停时更改按钮元素的颜色
示例
在此示例中,我们将在 div 悬停时更改按钮元素的颜色 -
立即学习“前端免费学习笔记(深入)”;
Change the color
Keep the mouse cursor inside the blue colored div to change the color of the orange box to yellow.











