css position是个很重要的知识点:
知乎Header部分:
知乎Header-inner部分:
position属性值:
fixed:生成绝对定位的元素,相对浏览器窗口进行定位(位置可通过:left...,right,top,bottom改变);与文档流无关,不占据空间(可能与其它元素重叠)
relative:生成相对定位的元素(相对于元素正常位置)(left,right,top,bottom);relative...的元素经常用作absolute的元素的容器块;原先占据的空间依然保留
absolute:生成绝对定位的元素(相对第一个已定位的父元素进行定位;若没有则相对)(left,right,top,bottom...没有定位,元素出现在正常的文件流中(left,right,top,bottom,z-index无效!)
inherit:继承从父元素的position值
fixed示例:
1 水平居中:
1.元素居中对齐(比如):
使用margin:0 auto;(上下margin为0,左右自动分配(居中!))!