【发布时间】:2014-02-02 16:29:38
【问题描述】:
我有这个条形图,当我悬停在特定条形图上时,我想将“测试 div”更改为不同的背景颜色和内容本身。
我在尝试制作一个元素时遇到了一些麻烦:悬停更改另一个元素。
我知道关于这个主题有很多类似的问题,但似乎没有一个对我有用。
HTML:
<div class="the-container">
<ul>
<li><a class="html" href="#"></a></li>
<li><a class="css" href="#"></a></li>
<li><a class="photoshop" href="#"></a></li>
<li><a class="illustrator" href="#"></a></li>
<li><a class="javascript" href="#"></a></li>
</ul>
<div class="test"><p>Hello</p></div>
</div>
CSS:
.the-container { width:300px; height:250px; background-color:#EEE; }
.the-container ul { margin:0; padding:0; list-style:none; }
.the-container li { width:40px; height:250px; margin:0 10px; position:relative; float:left;}
.the-container li a { position:absolute; bottom:0; width:100%; height:0; background-color:#ccc; border-top-left-radius: 5px; border-top-right-radius: 5px;}
.the-container li a.html:hover { background-color:#111; }
.the-container li a.css:hover { background-color:#ef3ef3; }
.the-container li a.photoshop:hover { background-color:#be3be3; }
.the-container li a.illustrator:hover { background-color:#cd3cd3; }
.the-container li a.javascript:hover { background-color:#888; }
div.test{width:300px; height: 30px; background-color:#BBB; position: relative; clear:both; line-height:2; margin-top:-16px;}
div.test p {text-align: center;}
a.html:hover ~ div.test{background-color:yellow;}
有什么想法吗? 非常感激!
【问题讨论】:
-
您在寻找纯 CSS 的解决方案吗?
-
兄弟选择器 (~) 只选择直接兄弟。您的
<div>不是<a>标签的兄弟。我不认为有任何方法可以用纯 CSS 做你想做的事 -
是的,这看起来像一个 javascript 任务
-
@StephenThomas 是对的,CSS 无法做到这一点。
-
正如@StephenThomas 所说,你不能只使用 CSS,因为你需要为父
ul退一步@
标签: html css hover html-lists