简体   繁体   English

使低于绝对位置div的元素可点击

[英]Make elements below absolute positioned div clickable

I am working on a project where I need to upload screenshots that are copy pasted into the browser. 我正在做一个项目,我需要上传复制粘贴到浏览器中的屏幕截图。 The system works but I have a problem to click the images to show them in full-screen. 该系统可以运行,但是单击图像以全屏显示它们时出现问题。

I made a JSFiddle of what it looks like: 我对它的外观做了一个JSFiddle

<div id="screenshot-container" class="vertical-scroll-div">
  <div id="editor" contenteditable="true"> </div>
  <img class="screenshot" src="https://blog.xenproject.org/wp-content/uploads/2014/10/Testing.jpg" /> 
  <img class="screenshot" src="https://blog.xenproject.org/wp-content/uploads/2014/10/Testing.jpg" /> 
  <img class="screenshot" src="https://blog.xenproject.org/wp-content/uploads/2014/10/Testing.jpg" /> 
  <img class="screenshot" src="https://blog.xenproject.org/wp-content/uploads/2014/10/Testing.jpg" /> 
  <img class="screenshot" src="https://blog.xenproject.org/wp-content/uploads/2014/10/Testing.jpg" /> 
</div>

.vertical-scroll-div {
    width: 100%;
    padding-top: 10px;
    height: 220px;
    min-height: 220px;
    overflow-x: auto;
    white-space: nowrap;
    border: 2px dashed #a9a9a9;
}
#editor {
    position: absolute;
    top: 0px;
    width: 100%;
    height: 220px;
    outline: 0;
}
.screenshot {
    margin-left: 10px;
    height: 200px;
    width: 200px;
    max-height: 200px;
    max-width: 200px;
}
.screenshot:hover {
    cursor: pointer;
    border: solid 2px #3498db;
}

The editor div can't be used as parent because it will be cleared when inserting a new image . 编辑器div不能用作父对象,因为插入新image时会清除它。

Hope someone got an idea. 希望有人知道。

Thanks 谢谢

Just add these properties to the .screenshot selector: 只需将这些属性添加到.screenshot选择器中即可:

.screenshot {
   position: relative;
   z-index: 10;
}

use this css 使用这个CSS

.screenshot {
    height: 200px;
    margin-left: 10px;
    max-height: 200px;
    max-width: 200px;
    position: relative;
    width: 200px;
    z-index: 5;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM