2022/8/11
学习进度
css(3) 50:14
盒子模型
分两种
box-sizing: content-box;
改变 border , padding 会改变元素的高宽
box-sizing: border-box;
改变 border , padding 不会改变元素的高宽
位置
position
① : static
position : static
这是默认的正常布局 , 改变 top , bottom , right , left , z-index 均无效
② : relative
position : relative
在原来的位置上进行 相对的改动 改变 , 并且原来的位置并不会被补上
举例 :
.div-inner-2{
display : inline-block
position : relative;
top : 10px;
left : -100px;
}
注意 : top: 10px , 是指 从上往下 移动 10px ; left : -100px 就相当于从右往左移动 100px.
③ : absolute
position : absolute
top : xxx px;
left : xxx px;
...
找到第一个离它最近的非 static 状态的祖先节点 , 相对于这个祖先节点四个边界的偏移量
④ : fixed
相对于屏幕视口的位移
y 总举了个网页傍边 “回到顶部” 的例子
.div-inner-2 {
width: 30px;
height: 100px;
background-color: darkgreen;
display: inline-block;
position: fixed;
color: white;
text-align: center;
top: 500px;
right: 0;
}
⑤ : sticky
一个很有趣的特效
.div-inner-1{
position : sticky;
top : 10px ; /*粘住后上方预留的位置*/
}
.div-inner-3{
position : sticky;
bottom : 10px ; /*粘住后下方预留的位置*/
}