堆叠的 div 需要活动的 z-index 悬停状态

发布于 2024-12-23 13:56:56 字数 683 浏览 0 评论 0原文

如果您查看我的页面位于此处,您可以看到堆叠的 div。它们向左浮动并具有负的右边距。当您将鼠标悬停在它们上方时,它们的 z 索引将为 100,将它们带到堆栈的顶部。然而,当您从左向右移动时,您会注意到开始堆叠的那一列仍然位于悬停的那一列的后面,因此您之前悬停过的那一列落在堆栈后面,使其右列或左列不可见。

我解决这个问题的想法是给每个“活动”卡一个 z-index 99,同时让卡处于正常状态 z-index 98。但是,它不起作用:-(

你有什么想法来解决我的困境吗?

.card {
margin-right:-670px;
float:left;
width:700px;
height:500px;
background:#EEE;
-moz-box-shadow: 2px 2px 2px 2px #000;
-webkit-box-shadow: 2px 2px 2px 2px #000;
position:relative;
z-index:98;
}

.card:visited {
z-index:99;
}

.card:hover {
z-index:100;
}

编辑:

这就是我的最终产品的样子,谢谢您的建议,但它们并不是答案

。此处描述>

If you look at my page located here you can see the stacked divs. They are floated to the left and have a negative right margin. Whe you hover over them they are given a z-index of 100 bringing them to the top of the stack. However, when you go from left to right you notice that the one that had began the stack is still right behind the hovered one, so the one you had hovered over previously falls behind the stack, making it's right or left column invisible.

My idea to solve this was to give each "active" card a z-index of 99 while having the cards in their normal state z-index 98. However, it's not working :-(

Do you have any ideas to solve my dilemma?

.card {
margin-right:-670px;
float:left;
width:700px;
height:500px;
background:#EEE;
-moz-box-shadow: 2px 2px 2px 2px #000;
-webkit-box-shadow: 2px 2px 2px 2px #000;
position:relative;
z-index:98;
}

.card:visited {
z-index:99;
}

.card:hover {
z-index:100;
}

Edit:

This is what my end product will look like. Thank you for the suggestions, but they aren't quite answers.

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

止于盛夏 2024-12-30 13:56:56

您意识到“活动”翻译为“当前正在被单击”,对吧?

我不明白如何在没有 jquery 或 javascript 的情况下完成你想要的事情。

You realize that "active" translates to "is currently being clicked", Right?

I don't see how there's anyway to accomplish what you want without jquery or javascript.

你的他你的她 2024-12-30 13:56:56

采用不同的方法可能会取得更好的成功。

像您已经做的那样,让您的卡片适合作为薄 div 的背景,但也具有完整的卡片可见性:隐藏在相同位置。您将鼠标悬停在卡片边缘并更改关联完整卡片的可见性以显示。鼠标移开,可见性再次隐藏。

试图将它们堆叠起来使它们全部可见,等等都是自找麻烦:)

You might have better success with a different approach.

Have your cards fit as background within thin div's as you already do, but also have full card visibility:hidden at same position. You mouse over card edge and change the visibility to show for the associated full card. Mouse off and visibility goes hidden again.

trying to stack them keeping them all visible, etc is begging for trouble :)

dawn曙光 2024-12-30 13:56:56

请参阅这里获取免费的js实现你想要的方式。我同意zagnut关于使用图像作为div背景的观点,请查看这个寻找实现这一目标的方法。我还建议对您的 html 进行常规清理

See here for a js free way of achieveing what you want. I agree with zagnut about using the images as a background to your divs look at this for a way to achieve that. I would also recomend a general cleanup of your html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文