xgqfrms™, xgqfrms® : xgqfrms's offical website of cnblogs! xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!

CSS position fixed All In One

CSS position fixed All In One

fixed 元素会被移出正常文档流,并不为元素预留空间,而是通过指定元素相对于屏幕视口(viewport)的位置来指定元素位置。
元素的位置在屏幕滚动时不会改变。
打印时,元素会出现在的每页的固定位置。
fixed 属性会创建新的层叠上下文。

改变 fixed 视口(定位参考点) ✅ ⚠️

当元素祖先的 transform, perspective 或 filter 属性非 none 时,容器由视口改为该祖先。

https://developer.mozilla.org/en-US/docs/Web/CSS/position

https://developer.mozilla.org/zh-CN/docs/Web/CSS/position

position fixed

相对于什么参考进行定位
如何改变定位的参考

https://www.ruanyifeng.com/blog/2019/11/css-position.html

fixed表示,相对于视口(viewport,浏览器窗口)进行偏移,即定位基点是浏览器窗口。

CSS position fixed 不相对网页定位

当元素祖先的 transform 属性非 none 时,定位容器由视口改为该祖先。

就是指定了 position:fixed 的元素,如果其祖先元素存在非 none 的 transform 值 ,那么该元素将相对于设定了 transform 的祖先元素进行定位。

https://segmentfault.com/a/1190000023048557

https://www.cnblogs.com/coco1s/p/7358830.html

demos

(🐞 反爬虫测试!打击盗版⚠️)如果你看到这个信息, 说明这是一篇剽窃的文章,请访问 https://www.cnblogs.com/xgqfrms/ 查看原创文章!

refs



©xgqfrms 2012-2021

www.cnblogs.com/xgqfrms 发布文章使用:只允许注册用户才可以访问!

原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!


posted @ 2022-02-10 11:12  xgqfrms  阅读(50)  评论(1编辑  收藏  举报