作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我从 3 个 div 组合创建了一个六边形。我想将鼠标悬停在六边形和所有 3 个 div 上以更改颜色。
<div class="hex" >
<div class="left" ></div>
<div class="middle" ></div>
<div class="right" ></div>
</div>
.hex {
float: left;
margin-right: -26px;
margin-bottom: -50px;
}
.hex .left {
float: left;
width: 0;
border-right: 60px solid #6C6;
border-top: 104px solid transparent;
border-bottom: 104px solid transparent;
}
.hex .left:hover {
border-right: 60px solid yellow;
}
.hex .middle {
float: left;
width: 124px;
height: 208px;
background: #6C6;
}
.hex .middle:hover {
background-color: yellow;
}
.hex .right {
float: left;
width: 0;
border-left: 60px solid #6C6;
border-top: 104px solid transparent;
border-bottom: 104px solid transparent;
}
.hex .right:hover {
border-left:60px solid yellow;
}
如您所见,目前我只能针对六边形的每个元素,而不是整个六边形。
最佳答案
CSS 无法关联和组合分离的单个元素的:hover
状态。
在这种情况下,您可以将 :hover
状态关联到每个选择器中的整个 .hex
元素。在 :hover
之后,您可以添加更多子选择器:
.hex:hover .left
(而不是
).hex .left:hover
完整代码:
.hex {
float: left;
margin-right: -26px;
margin-bottom: -50px;
}
.hex .left {
float: left;
width: 0;
border-right: 60px solid #6C6;
border-top: 104px solid transparent;
border-bottom: 104px solid transparent;
}
.hex:hover .left {
border-right: 60px solid yellow; /* or simply: border-right-color: yellow; */
}
.hex .middle {
float: left;
width: 124px;
height: 208px;
background: #6C6;
}
.hex:hover .middle {
background-color: yellow;
}
.hex .right {
float: left;
width: 0;
border-left: 60px solid #6C6;
border-top: 104px solid transparent;
border-bottom: 104px solid transparent;
}
.hex:hover .right {
border-left: 60px solid yellow; /* or simply: border-left-color: yellow; */
}
<div class="hex">
<div class="left"></div>
<div class="middle"></div>
<div class="right"></div>
</div>
关于html - 我想在父 div 中定位多个 div,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26339163/
使用登录后,我想吐出用户名。 但是,当我尝试单击登录按钮时, 它给了我力量。 我看着logcat,但是什么也没显示。 这种编码是在说。 它将根据我在登录屏幕中输入的名称来烘烤用户名。 不会有任何密码。
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎是题外话,因为它缺乏足够的信息来诊断问题。 更详细地描述您的问题或include a min
我是一名优秀的程序员,十分优秀!