CSS 响应式设计中的固定位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15650056/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 22:13:21  来源:igfitidea点击:

Fixed Position in responsive design

cssscrollresponsive-designcss-position

提问by User_coder

I am using responsive framework 1140px. In the mobile version I have to fix the position of a logo but not have it overlap the content on scroll. Basically fix the position but don't fix the image on scroll, can this be achieved?

我正在使用响应式框架 1140px。在移动版本中,我必须固定徽标的位置,但不能使其与滚动内容重叠。基本上固定位置但不固定滚动图像,这可以实现吗?

回答by Daniel Imms

You want to use position:absolute

你想用 position:absolute

  • position:fixedfixes the element to the screen, so it will not move when you scroll (it's fixed to the window).

  • position:absolutefixes the element based on the closest ancestorthat is not position:static, so it will move when you scroll the page (it's fixed to the page).

  • position:fixed将元素固定在屏幕上,因此滚动时它不会移动(它固定在窗口上)。

  • position:absolute基于最接近的ancestor而不是固定元素position:static,所以当你滚动页面时它会移动(它固定在页面上)。

回答by Bernie

It appears that you want is position: absolute, the difference being that absolute images do not move while scrolling.
http://www.impressivewebs.com/absolute-position-css/

看起来您想要的是position: absolute,不同之处在于绝对图像在滚动时不会移动。
http://www.impressivewebs.com/absolute-position-css/

It's worth taking a look at this link in order to see the differences between relative, absolute, and fixed positioning:
http://css-tricks.com/absolute-relative-fixed-positioining-how-do-they-differ/

值得一看这个链接,以了解相对定位、绝对定位和固定定位之间的差异:http:
//css-tricks.com/absolute-relative-fixed-positioining-how-do-they-differ/