[英]Apply z-index to div overflow (scrollbar)
I have a div with horizontal scrollbar and an image (or other div) over entire page (with position absolute).我在整个页面上有一个带有水平滚动条的 div 和一个图像(或其他 div)(位置绝对)。 The prolem is I want to be able to scroll the div which is beside the image.
问题是我希望能够滚动图像旁边的 div。 For
a
links I positioned them relative and applied z-index.对于
a
链接我位于它们相对并且施加z索引。 How can I apply z-index
only for div's scrollbar?如何仅对 div 的滚动条应用
z-index
? So, I want the div to be behind the image.所以,我希望 div 位于图像后面。
Screenshoot Example:屏幕截图示例:
Visual Example:视觉示例:
<div style="overflow-x: scroll; overflow-y: hidden; width: 300px; height: 130px; white-space: nowrap;"> s sd ds fsd fs df s fs fds fsd fsd fsd fds f sdf sd fs fsd f sdf sd f sdf sd f sdf ds fsdf sf ds f sdf dsf sdf s df sdf sdf ds fsd fsdf sd fds <br/>fsd fds f sd fsd fsd fds fs df sd f sd fds f sd f sdf sd f ds fsdf s df sd fs df sdfsd f <br/>sdf ds f sdf sd f dsf sd fds f ds fs df sd fds f ds f sd fs df sd fsdfs df sdf sd fs df sd fsd <br/>sdf ds f sdf sd f dsf sd fds f ds fs df sd fds f ds f sd fs df sd fsdfs df sdf sd fs df sd fsd <br/>sdf ds f sdf sd f dsf sd fds f ds fs df sd fds f ds f sd fs df sd fsdfs df sdf sd fs df sd fsd </div> <div style="position: absolute; top: 0px; left: 0px;"> <img src="http://www.wabmo.com/Album/watermark/watermarks/Sample-trans.png" width="300"/> </div>
Thank you!谢谢!
Add pointer-events:none
to another div which consist of img
tag.将
pointer-events:none
添加到另一个包含img
标签的 div。
<div style="position: absolute; top: 0px; left: 0px;pointer-events:none;">
<img src="http://www.wabmo.com/Album/watermark/watermarks/Sample-trans.png" width="300;"/>
</div>
I hope this helpful for you我希望这对你有帮助
.sample
{
position: absolute; top: 0px; left: 0px;pointer-events:none;
}
<div style="overflow-x: scroll; overflow-y: hidden; width: 300px; height: 130px; white-space: nowrap; ">
s sd ds fsd fs df s fs fds fsd fsd fsd fds f sdf sd fs fsd f sdf sd f sdf sd f sdf ds fsdf sf ds f sdf dsf sdf s df sdf sdf ds fsd fsdf sd fds
<br/>fsd fds f sd fsd fsd fds fs df sd f sd fds f sd f sdf sd f ds fsdf s df sd fs df sdfsd f
<br/>sdf ds f sdf sd f dsf sd fds f ds fs df sd fds f ds f sd fs df sd fsdfs df sdf sd fs df sd fsd
<br/>sdf ds f sdf sd f dsf sd fds f ds fs df sd fds f ds f sd fs df sd fsdfs df sdf sd fs df sd fsd
<br/>sdf ds f sdf sd f dsf sd fds f ds fs df sd fds f ds f sd fs df sd fsdfs df sdf sd fs df sd fsd
</div>
<div class='sample'>
<img src="http://www.wabmo.com/Album/watermark/watermarks/Sample-trans.png" width="300"/>
</div>
You can try this code for text content div您可以将此代码用于文本内容 div
z-index: 100;
position: relative;
Demo link https://jsfiddle.net/m5p5ngep/2/演示链接https://jsfiddle.net/m5p5ngep/2/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.