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 之外


- 如何向 ipc 渲染器发送添加回调 2022-01-01
- 如何显示带有换行符的文本标签? 2022-01-01
- 是否可以将标志传递给 Gulp 以使其以不同的方式 2022-01-01
- 我不能使用 json 使用 react 向我的 web api 发出 Post 请求 2022-01-01
- 使用 iframe URL 的 jQuery UI 对话框 2022-01-01
- 为什么我的页面无法在 Github 上加载? 2022-01-01
- 为什么悬停在委托事件处理程序中不起作用? 2022-01-01
- 从原点悬停时触发 translateY() 2022-01-01
- 如何调试 CSS/Javascript 悬停问题 2022-01-01
- 在不使用循环的情况下查找数字数组中的一项 2022-01-01