how to put Image outside of its parent div when hover(悬停时如何将图像放在其父 div 之外)
问题描述
我有一个可滚动的 div
,其中包含一些 img
元素.我为图像添加了 width
和 height
的悬停效果.它工作正常,但图像卡在 #scroller
div
中.我希望图像在鼠标悬停时脱离滚动条 div
.我怎样才能做到这一点 ?
I have a scrollable div
with some img
elements in it. I have added a hover effect of width
and height
for images. It works fine, but image get stuck in #scroller
div
. I want that the image get out of scroller div
when mouse over it. How can I do that ?
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>
我没有尝试任何东西,因为我不知道.
I didn't try anything because I have no idea.
推荐答案
如果您打算仅使用 CSS,一种方法是将悬停时图像的位置更改为绝对位置.
If you are planning to use CSS only, one approach could be to change the position of the image on hover to absolute.
看这个例子: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 来获得更好的结果.
Otherwise you could use javascript to have achieve better results.
这篇关于悬停时如何将图像放在其父 div 之外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:悬停时如何将图像放在其父 div 之外


基础教程推荐
- 角度Apollo设置WatchQuery结果为可用变量 2022-01-01
- 在 JS 中获取客户端时区(不是 GMT 偏移量) 2022-01-01
- 当用户滚动离开时如何暂停 youtube 嵌入 2022-01-01
- 响应更改 div 大小保持纵横比 2022-01-01
- 有没有办法使用OpenLayers更改OpenStreetMap中某些要素 2022-09-06
- 动态更新多个选择框 2022-01-01
- 在for循环中使用setTimeout 2022-01-01
- Karma-Jasmine:如何正确监视 Modal? 2022-01-01
- 我什么时候应该在导入时使用方括号 2022-01-01
- 悬停时滑动输入并停留几秒钟 2022-01-01