CSS进阶(十一)position:fixed

固定定位元素的包含快是根元素

类似于无依赖的绝对定位,利用无依赖的固定定位也可以在元素内部实现一个fixed定位

<div class="father">
 <div class="right">
 &nbsp;<div class="son"></div>
 </div>
</div>
.father {
 width: 300px; height: 200px;
 position: relative;
}
.right {
 height: 0;
 text-align: right;
 overflow: hidden;
}
.son {
 display: inline;
 width: 40px; height: 40px;
 position: fixed;
 margin-left: -40px;
} 

可以使用absolute来模拟一个fixed,具体实现是用一个div作为body的子元素,充当滚动容器。但需要谨慎使用

猜你喜欢

转载自www.cnblogs.com/goOtter/p/9814070.html