【发布时间】:2014-10-23 09:08:54
【问题描述】:
我在对不同的 HTML 元素应用悬停效果时遇到了麻烦,例如更改 DIV 边框的颜色及其父 DIV 的背景颜色。
我的 HTML 代码如下所示:
<div id="time-later">
<div class="time-arrow"></div>
<p>later</p>
</div>
匹配的 CSS 代码:
#time-later {
height: 35px;
width: calc(25% - (15px/4));
}
#time-later p {
display: block;
width: calc(100% - 14.5px);
margin-right: 14.5px;
}
#time-later .time-arrow {
float: right;
width: 0;
height: 0;
border-top: 17.5px solid transparent;
border-left: 14.5px solid green;
border-bottom: 17.5px solid transparent;
z-index: 1;
}
一些样式
#time-later p {
text-align: center;
line-height: 35px;
background-color: green;
}
#time-later p:hover {
background-color: red;
}
#time-later p:active {
color: #FFF;
background-color: gray;
}
当我将鼠标移到 #time-later 元素上时,我希望 p 元素的背景和 .arrow 元素的边框以相同的颜色着色。
是否有任何纯 CSS 解决方案来实现这样的目标?我知道放置图像会更容易,但我正在寻找纯 CSS 的解决方案。感谢您的帮助!
【问题讨论】:
标签: html css hover pseudo-element