gpt4 book ai didi

html - 悬停时如何将图像放在其父div之外

转载 作者:行者123 更新时间:2023-11-28 17:38:26 25 4
gpt4 key购买 nike

我有一个可滚动的 div,里面有一些 img 元素。我为图像添加了 widthheight 的悬停效果。它工作正常,但图像卡在 #scroller div 中。我希望当鼠标悬停在图像上时图像从滚动条 div 中消失。我怎样才能做到这一点 ?

CSS:

#scroller {
width:100%;
border:1px solid black;
white-space:nowrap;
height:130px;
display:inline-block;
overflow-x:scroll;
overflow-y:hidden;
}
img {
width:128px;
height:128px;
}
img:hover {
width : 192px;
height:192px;
}

HTML:

<div id="scroller">
<img/>
<img/>
<img/>
<img/> ...and some more images
</div>

我没有尝试任何东西,因为我不知道。

最佳答案

如果您打算只使用 CSS,一种方法是将悬停时图像的位置更改为绝对位置。

看这个例子:http://jsfiddle.net/Vn8M6/3/

#scroller {
width:100%;
height:100%;
border:1px solid black;
white-space:nowrap;
height:130px;
display:inline-block;
overflow-x:scroll;
overflow-y:hidden;
}

img {
width:128px;
height:128px;
transition: ease-in-out 0s;
-webkit-backface-visibility: hidden;
-webkit-transform: translateX(0);
z-index:1;
background-color:grey;
}

img:nth-child(2) {
background-color:yellow;
z-index:2;
}

img:nth-child(3) {
background-color:red;
z-index:3;
}

img:nth-child(4) {
background-color:blue;
z-index:4;
}

img:hover {
width : 192px;
height:192px;
position:absolute;
top:0;
}

否则你可以使用 javascript 来获得更好的结果。

关于html - 悬停时如何将图像放在其父div之外,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24655027/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com