简体   繁体   English

如何使parent1的子元素具有比父2的子元素更高的z索引(与其他父元素具有相同的z索引)?

[英]How to make child elements from parent1 have a higher z-index than child elements from parent 2 (with same z-index as other parent)?

I have the following HTML: 我有以下HTML:

HTML 的HTML

<div id="map">
  <div class="parent">
    <svg>
      <div class="child"></div>
      <div class="child"></div>
    </svg>
  </div>
  <div class="parent">
    <svg>
      <div class="child"></div>
      <div class="child"></div>
    </svg>
  </div>
</div>

CSS 的CSS

.parent {
  position: absolute;
  top: 0;
  left: 0;
  width: 1000px;
  height: 700px;
}

svg {
  overflow: hidden;
  width: 100%;
  height: 100%;
}

Abbreviations: 缩略语:

first parent-element: p1 第一个父元素: p1

second parent-element: p2 第二个父元素: p2

child-elements from p1: c1 来自p1的子元素: c1

child-elements from p2: c2 来自p2的子元素: c2

Background info: 背景信息:

Both parent-elements are positioned exactly above each other. 两个父元素都位于彼此的正上方。 It seems that the p2 is "a complete layer above the p1". p2似乎是“ p1之上的完整层”。

Problem/Question: 问题/问题:

Currently i can NOT click on ANY c1. 目前,我无法单击任何c1。 No chance. 没有机会。 The p2 seems to be a complete layer above the p1. p2似乎是p1之上的完整层。 How do I manage that c2 still are above c1 BUT I am able to click on c1 if there are no c2 directly above them. 我如何管理c2仍在c1之上,但是如果在它们的正上方没有c2,我可以单击c1。

You could add pointer-events: none to the .parent divs and then add pointer-events:all to the .child divs. 您可以将pointer-events: none添加到.parent div,然后将pointer-events:all添加到.child div。

This would mean only the actual children can be clicked. 这意味着只能单击实际的孩子。 If there is no c2 then c1 should be clickable 如果没有c2,则c1应该是可点击的

something like this? 这样的东西? http://jsfiddle.net/ekL6632c/1/ http://jsfiddle.net/ekL6632c/1/

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

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