position:fixed 相对于父元素定位

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

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

解决办法:

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

示例:

header.fixed{
    position: fixed;
    top: 0;
    width: 100%;
    max-width: 640px;       
}
原文地址:https://www.cnblogs.com/tujia/p/14657232.html