简体   繁体   English

带有剪切路径的div内的元素不适用于绝对位置

[英]Element inside div with clip-path doesn't work with absolute position

I am trying to add a tooltip in a div which has clip-path: polygon . 我正在尝试在具有clip-path: polygon的div中添加一个工具提示。 The problem is that I can't give position: absolute to my tooltip (to be above the parent div). 问题是我不能给position: absolute我的工具提示的position: absolute (位于父div上方)。 When parent div doesn't have a clip-path regule everything works fine. 当parent div没有剪切路径规则时,一切正常。

Something like that: 像这样:

<div>
<div class="house">
  <div class="tooltip">
   ITEM 1
   </div>
 </div>
</div>


.house {
 height: 91px;
 left: 72px;
 top: 81px;
 width: 57px;
 background-color: #fe0000;
}

.tooltip {
  background-color: #aaa;
  width: 150px;
  height: 30px;
  position: absolute;
  top: -20px;
}

Thanks in advance for your help. 在此先感谢您的帮助。

Adding "position: relative;" 添加“ position:relative;” to ".house" should solve it. 到“ .house”应该解决它。

Position absolute in CSS relates to the first parent element where the position is not static. CSS中的绝对位置与位置不是静态的第一个父元素有关。 The default value in CSS for position is Static, that's why it probably does not work for you. CSS中位置的默认值为“静态”,这就是为什么它可能对您不起作用的原因。

The fiddle: https://jsfiddle.net/anebkb42/2/ 小提琴: https : //jsfiddle.net/anebkb42/2/

.house {
  height: 91px;
  left: 72px;
  top: 81px;
  width: 57px;
  background-color: #fe0000;
  position: relative;
}

.tooltip {
  background-color: #aaa;
  width: 150px;
  height: 30px;
  position: absolute;
  top: -20px;
}

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

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