CSS:悬停一个元素,多个元素的效果?
我正在寻找解决悬停问题的方法。
<div class="section">
<div class="image"><img src="myImage.jpg" /></div>
<div class="layer">Lorem Ipsum</div>
</div>
现在,图像和图层这两个类都有边框。正常和悬停时两者都有不同的颜色。 有没有办法做到这一点,所以如果我将鼠标悬停图层类,则图层和图像类悬停边框颜色都处于活动状态?反之亦然?
I'm looking for a method for my hovering issue.
<div class="section">
<div class="image"><img src="myImage.jpg" /></div>
<div class="layer">Lorem Ipsum</div>
</div>
Now, both classes, image and layer, have borders. Both have different color for normal and hover.
Is there way to make it, so if I hover layer class, both layer and image class hovering border color is active? And vise versa?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
为此,您不需要 JavaScript。
一些 CSS 就可以做到。这是一个例子:
You don't need JavaScript for this.
Some CSS would do it. Here is an example:
这在 Firefox、Chrome 和 IE8 中对我有用……
你可能也想用 IE6 来测试它(我不确定它是否能在那里工作)。
This worked for me in Firefox and Chrome and IE8...
... you may want to test this with IE6 as well (I'm not sure if it'll work there).
我认为对你来说最好的选择是将两个 div 用另一个 div 括起来。然后你可以通过CSS按照以下方式制作它:
I think the best option for you is to enclose both divs by another div. Then you can make it by CSS in the following way:
这并不难实现,但是需要使用 javascript
onmouseover
函数。伪脚本:使用您自己的颜色。您还可以在 mouseover 命令中引用 javascript 函数。
This is not difficult to achieve, but you need to use the javascript
onmouseover
function. Pseudoscript:Use your own colors. You can also reference javascript functions in the mouseover command.
我认为您需要使用 JavaScript 来完成此任务。
jQuery:
相应地调整值和元素 id :)
You'd need to use JavaScript to accomplish this, I think.
jQuery:
Adjust the values and element id's accordingly :)
你也可以这样做。例如,您有一个链接附加到另一个链接,并且您想在将鼠标悬停在一个链接上时显示这两个链接,您只需指定每个链接的功能,然后在将两个链接悬停时立即显示即可。
You can also do it like this. for example you have a link attached to another link and you want to show both at hovering at one you can do it simply by specifying each individual's functions then at once at hovering both.
或
注意
父元素状态只能影响子元素状态
所以你可以使用:
但你不能使用
OR
NOTE
Parent element state can only affect a child's element state
so you can use:
but you can not use