CSS: Hover one element, effect for multiple elements?(CSS:悬停一个元素,多个元素的效果?)
问题描述
我正在寻找解决悬停问题的方法.
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?
推荐答案
你不需要 JavaScript.
You don't need JavaScript for this.
一些 CSS 可以做到这一点.这是一个例子:
Some CSS would do it. Here is an example:
<html>
<style type="text/css">
.section { background:#ccc; }
.layer { background:#ddd; }
.section:hover img { border:2px solid #333; }
.section:hover .layer { border:2px solid #F90; }
</style>
</head>
<body>
<div class="section">
<img src="myImage.jpg" />
<div class="layer">Lorem Ipsum</div>
</div>
</body>
</html>
这篇关于CSS:悬停一个元素,多个元素的效果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CSS:悬停一个元素,多个元素的效果?


基础教程推荐
- 在 contenteditable 中精确拖放 2022-01-01
- 检查 HTML5 拖放文件类型 2022-01-01
- npm start 错误与 create-react-app 2022-01-01
- Fabric JS绘制具有活动形状的多边形 2022-01-01
- 原生拖动事件后如何获取 mouseup 事件? 2022-01-01
- Bootstrap 模态出现在背景下 2022-01-01
- 如何添加到目前为止的天数? 2022-01-01
- Bokeh Div文本对齐 2022-01-01
- 即使用户允许,Gmail 也会隐藏外部电子邮件图片 2022-01-01
- fetch 是否支持原生多文件上传? 2022-01-01