position:static,absolute,relative,sticky
position:fixed;固定定位
a:参照物,浏览器窗口。
b:不占据空间脱离布局流。
让一个元素在浏览器窗口左右上下居中:
方法一:position:fixed;
left:50%
top:50%
margin-left:-元素宽度一般;
margin-top:-元素高度一般;
方法二:position:fixed;
left:0; right:0;
top:0; bottom:0;
margin:auto;
让子元素在父元素上下左右居中:
(1):让父元素形成参照物 position:relative;
(2) :子元素定位 position:absolute;
left:0;right:0;
top:0;bottom:0;
margin:auto;
粘性定位:position:sticky;
吸顶效果:添加: position:sticky;
top:0;
宽超出版心的banner实现方法:
(1)版心设置参照物 position:relative;
(2)图片添加 position:absolute;
left:50%;
margin-left:-图片宽度的一半
定位
最新推荐文章于 2024-07-14 16:50:03 发布