简体   繁体   English

固定的元素位置与父级相关,而不是与视口相关

[英]Element position fixed is related to parent instead to the viewport

trying to achieve: 试图实现:

position element in fixed right and top relative to the viewport 固定右侧和顶部相对于视口的位置元素

what I am doing: 我在做什么:

  • set position: fixed; 设定位置:固定; to the element 对元素

  • calculate the right and the top related and set it on the element 计算右侧和顶层相关并将其设置在元素上

what happen? 发生什么事?

  • element any where is act as i wanted 元素任何在哪里按我的意愿行事

  • but Element with the same styling (fixed position and right & top) in modal get positioned relative to he's parent (it's happen on bootstrap modal) 但是在模态中具有相同样式(固定位置和右侧和顶部)的元素相对于他的父级定位(它发生在自举模式上)

code example element style: 代码示例元素样式:

.fixed-floater {
  top: 300px;
  right: 151px;
  text-align: left;
  display: block;
  min-width: 180px;
  position: fixed;
  z-index: 999;
  padding: 4px;
}

images: 图片: http://s3.postimg.org/u2kraeyzn/modal_error.png

what happen (as i understand) 发生了什么(据我所知)

modal container has (from bootstrap) defaults of transform: translate(0, 0); 模态容器有(来自bootstrap)默认的transform:translate(0,0);

by the w3 specification : w3规范

element with position:fixed are always relative to the initial containing block. 具有position:fixed的元素始终相对于初始包含块。

W3 Wiki W3 Wiki

Some values of these properties result in the creation of a containing block 这些属性的某些值导致创建包含块

and

For elements whose layout is governed by the CSS box model, any value other than none for the transform results in the creation of both a stacking context and a containing block. 对于布局由CSS框模型控制的元素,转换的除none之外的任何值都会导致创建堆叠上下文和包含块。 The object acts as a containing block for fixed positioned descendants. 该对象充当固定定位后代的包含块。 W3 Transform Specification W3转换规范

So by the mentioned above, the Translate transform is setting the modal as "the initial containing block" for the fixed element inside him instead of the body. 因此,通过上面提到的,Translate变换将模态设置为他内部的固定元素而不是主体的“初始包含块”。

TL;DR: TL; DR:

Override the specific modal's .modal-dialog with 用。覆盖特定模态的.modal-dialog

transform: none;

This could happen if there are any css keyframe animations written on any of its parent elements. 如果在其任何父元素上写入任何css关键帧动画,则可能发生这种情况。

Try removing the class written for keyframe animations and check. 尝试删除为关键帧动画编写的类并检查。 It might work. 它可能会奏效。

I think this fixed related to modal div. 我认为这与模态div有关。 check did you gave position:relative on modal div. 检查你给了position:relative对于模态div。 if you did this remove the position:relative and make the position:relative to view port 如果你这样做,删除位置:relative并使位置:相对于视口

like 喜欢

.view-port{
position:relative
}

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

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