html - 想要在 css3 中悬停另一个 div 时更改 div 的背景

标签 html css hover

我想在将鼠标悬停在另一个 Div 上时更改 Div 的背景,我试过了

HTML5部分:

<nav>
<div id="nav1"></div>
<a href="#"><div id="nav2"></div></a>
<a href="#"><div id="nav3"></div></a>
<a href="#"><div id="nav4"></div></a>
<a href="#"><div id="nav5"></div></a>
<a href="#"><div id="nav6"></div></a>
<div id="nav7"></div>
</nav>
<article>
<div id="nav8"></div>
</article>

我试过的 CSS 是

#nav2
{
float:left;
height:429px;
width:34px;
background:url(images/nav_02.gif) no-repeat;
}
#nav2:hover #nav8
{
float:left;
height:429px;
width:445px;
background:url(images/nav_08-nav_02_over.jpg) no-repeat;
}

但是没用... 我只需要用 css 来做,没有 javascript ..

最佳答案

CSS 选择器的工作方式是 Parent > Descendant

当你做的时候

#nav2:hover #nav8

这意味着#nav8 是#nav2 的后代,在您的标记中不是这种情况,因此该规则不适用

你必须使用 javascript 来做你想做的事。

关于html - 想要在 css3 中悬停另一个 div 时更改 div 的背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9001229/

相关文章:

html - 链接到页面底部附近的 anchor

html - 在 div 中包含图像

html - 使用 inappbrowser 输入类型文件

html - 来自网站管理员工具的 hreflang 问题

css - 我可以只使用数字来命名 CSS 类吗

html - 如何使图像随着悬停而淡化并显示文本?

jquery:嵌套标签和悬停()在 IE 中不起作用

html - 悬停子菜单不起作用

html - CSS 显示 :block will not render a div area as visable on @media screen width change

jquery - 制作一个带背景的按钮