CSS 布局相关


记录下这几天遇到的一些面试题

实现 3 栏垂直布局,并且指定顺序加载

元素 方向 高度
div1 底部 200px
div2 中部 auto
div3 顶部 100px

效果

image

思路

使用 【父相子绝】的方法,限定位置

代码

div1
div2
div3
body {
    margin: 0;
}
html, body, .wrapper {
    height: 100%;
}
.wrapper {
    width: 50px;
    position: relative;
}
.wrapper > div {
    width: 100%;
}
.div1 {
    height: 200px;
    background-color: aqua;
    position: absolute;
    bottom: 0;
}
.div2 {
    background-color: burlywood;
    position: absolute;
    top: 100px;
    bottom: 200px;
}
.div3 {
    height: 100px;
    background-color: beige;
    position: absolute;
    top: 0;
}
CSS