简体   繁体   English

CSS`Position:Fixed`不在滚动中移动

[英]CSS `Position: Fixed` Not Moving On Scroll

I tried to put a position: fixed on the div ".ais-search-header", but it does not move while on scroll. 我试图放置一个位置:固定在div“ .ais-search-header”上,但在滚动时不会移动。 I also try to drag it out from the parent div, but still did not work. 我也尝试将其从父div拖出,但仍然没有用。

URL: https://kickegg0.myshopify.com/search.searchdata?q=q Pass: tweast 网址: https ://kickegg0.myshopify.com/search.searchdata?q = q通过:tweast

There is a bug in Chrome and Firefox where position: fixed does not position relative to the screen when there is an ancestor element with the transform or backface-visibility attributes (or their webkit equivalents) set. Chrome和Firefox中存在一个错误,即position: fixedposition: fixedtransformbackface-visibility属性(或其Webkit等效项)的祖先元素时, position: fixed相对于屏幕的位置不正确。

Move the element you want absolutely positioned above the elements with those attributes. 使用这些属性将要绝对定位的元素移到元素上方。

A position: fixed element has no dependency to its parent container. position: fixed元素不依赖于其父容器。 Its position actually depends on the browser window. 它的位置实际上取决于浏览器窗口。 That means it won't move or scroll on page scroll. 这意味着它不会在页面滚动上移动或滚动。 It will be on top of the page. 它会在页面顶部。 But those under that element will scroll according to the page. 但是该元素下的内容将根据页面滚动。 If you want to move the container according to scroll, give it position: absolute like:- 如果要根据滚动移动容器,请给其position: absolute如:-

#parent {
    position: relative;
}
#container {
    position: absolute;
}

So that it will be inside the container and will move on page scroll. 这样它就可以在容器内并在页面滚动中移动。

Position 'fixed' positioning is based on your browser window so not move with scrolling. 位置“固定”位置基于您的浏览器窗口,因此不会随着滚动而移动。 if you want to move with scrolling use position 'absolute' 如果要滚动移动,请使用“绝对”位置

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

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