position:fixed 相对于父元素定位

不是真正的相对于父元素定位,只是解决 left:0的问题

问题:left:0时,相对于window居左了,想要的效果其实是相对于 body 居左

 

解决办法:

可以加 top 和 bottom,别加 left 和 right

 

示例:

header.fixed{
    position: fixed;
    top: 0;
    width: 100%;
    max-width: 640px;       
}

 

posted @ 2021-04-14 12:05  Tiac  阅读(779)  评论(0编辑  收藏  举报