【发布时间】:2017-12-29 06:00:31
【问题描述】:
我不确定不使用 JS 是否可行。
基本上,我试图创建一种效果,您将鼠标悬停在连续的图像上并且该图像亮起并且有关此的信息是下面显示的图像。 虽然图像翻转效果很简单,但在下面显示描述却很难实现。 我知道我可以将此作为工具提示,但所需的效果是出现在页面中。
查看示例
https://i.stack.imgur.com/CsB1A.png
我相信这样做的方法是将每个图像放入一个单独的子 div 中。 然后在这些子 div 之一的翻转时,让另一个信息 div 从“display:none”更改为“display:block”。
问题是如何让一个子 div 上的悬停选择器影响另一个子 div?
html, page {
margin: 0px;
padding: 0px;
width: 100%;
font-family: sans-serif;
}
.parent {
border: 1px solid fuchsia;
padding: 1%;
height: 360px;
width: 60%;
min-width: 600px;
max-width: 1200px;
margin: 0 auto;
display: flex;
flex-wrap: wrap;
justify-content: space-between;
}
.child {
display: block;
background: white;
height: 120px;
width: 120px;
border: 2px solid purple;
border-radius: 80px;
text-align: center;
line-height: 120px;
}
.child:hover {
background: cyan;
border: 2px solid cyan;
}
.p1 {
display: none;
}
.p2 {
display: none;
}
.p3 {
display: none;
}
.p4 {
display: none;
}
.1:hover ~ .p1{
display: block;
}
.2:hover ~ .p2{
display: block;
}
.3:hover ~ .p3{
display: block;
}
.4:hover ~ .p4{
display: block;
}
.childinfo {
width: 100%;
height: 200px;
border: 2px solid cyan;
margin-bottom: 0px;
padding: 1%;
text-align: center;
}
<html>
<body>
<div class="parent">
<div class="child 1">Child1</div>
<div class="child 2">Child2</div>
<div class="child 3">Child3</div>
<div class="child 4">Child4</div>
<div class="childinfo">
<br><strong>Child Info Div</strong>
<span class="p1">This is info about child 1 div</span>
<span class="p2">This is info about child 2 div</span>
<span class="p3">This is info about child 3 div</span>
<span class="p4">This is info about child 4 div</span>
</div>
</div>
</body>
</html>
【问题讨论】:
-
试一试 - 没用。与悬停选择器一起使用时,兄弟组合器可能不起作用?代码在原始帖子中更新。如果我遗漏了什么,请告诉我。
标签: html css css-selectors hover children