【发布时间】:2015-03-19 09:20:25
【问题描述】:
嗨
我有 5 个 div。 假设( div class="part1" class="part2" class="part3" class="part4" class="part5" 都向左浮动,宽度为:20%)所以它们对齐在一行中。
每个 div 包含 2 张图片,假设 image1 的 id 为“top”,image2 的 id 为“bottom”(分别在所有 div 中)。
现在我要做的是,我将所有具有 id“底部”的图像的不透明度设置为 0,并在图像“顶部”悬停时将“底部”不透明度更改为 1,将“顶部”不透明度更改为 0。
到目前为止它工作正常。
现在我想要的是那个 我想要第 1 部分 div 中的第三张图片,id 假设为 id="yellow"。
现在,当网络加载时,我想在第 1 部分中显示“顶部”id 图片。
当用户将鼠标悬停在第 1 部分 id="top" 图像上时,我想显示 id="bottom" 图像(直到现在我正在实现这一点)
现在,如果用户将鼠标悬停在第 2 部分、第 3 部分、第 4 部分、第 5 部分上,我想在第 1 部分中显示 id="yellow" 的图像。
我尝试使用伪选择器 +、~ 等,但很快我意识到它们仅在 div 分别位于另一个 div 下或父 div 内时才有效。但在我的情况下,第 1 部分在第 2 部分之前,依此类推..所以我不能更改订单。附:我知道 JS jquery 可能,但我不想使用它们。
一些代码
< div class="part1">
<img1 id="top"></img> colored image with happy child
<img2 id="bottom"></img> yellow image with sad child
<img3></img> plain yellow image
</div>
< div class="part2">
<img1 id="top"></img> colored image with happy child
<img2 id="bottom"></img> yellow image with sad child
</div>
<div class="part3">
<img1 id="top"></img> colored image with happy child
<img2 id="bottom"></img> yellow image with sad child
</div>
< div class="part4">
<img1 id="top"></img> colored image with happy child
<img2 id="bottom"></img> yellow image with sad child
</div>
< div class="part5">
<img1 id="top"></img> colored image with happy child
<img2 id="bottom"></img> yellow image with sad child
</div>
现在我想在第 1 部分中显示黄色 id 图像,当我将鼠标悬停在第 2 部分 - 第 5 部分时 IE。我不想仅在第 1 部分中分别显示 id 为 top 和 bottom 的图像,仅显示 id 为黄色的图像
【问题讨论】:
-
你需要一些js代码
-
@abidibo 我知道,但只有纯 html css 可能吗?
-
@AmmarUlHassan:根据我对您所追求的内容的理解,js 将是采用的方法(即使 css 是可能的,它也会是错误且非常不干净的代码)。坚持他们要做的事情。 - js 就是为此而生的。
-
我想当悬停 .part2 时,您想要在 .part1、.part3 和 .part4 中显示黄色图像,所以不,我不这么认为。你可以用伪元素做一些事情,将它们定位为绝对元素并覆盖其他 div,但是 1 - 你只有 2 个伪元素元素,而你需要 3 个。 2 - 你不能计算坐标,所以你需要所有元素都是绝对定位的并具有固定尺寸。在使用 js 时,这是一项非常简单的任务。
-
实际上我知道 JS 会做到这一点,但我使用 html css 实现了所有这些功能,所以对于我项目中的最后一项任务,我想坚持使用 html css.@jbutler483。