# 布局
# CSS哪些属性脱离文档流
position:absolute
position:fixed
float:left
float:right
注意,position: sticky
是不脱离文档流的。
# div+css的布局较table布局有什么优点?
符合W3C标准,代码结构清晰明了,结构、样式和行为分离,带来足够好的可维护性。
布局精准,网站版面布局修改简单。
加快了页面的加载速度(最重要的)(在IE中要将整个table加载完了才显示内容)。
易于优化( SEO )搜索引擎更友好,排名更容易靠前。
# 元素竖向的百分比设定是相对于容器的高度吗?
元素竖向的百分比设定是相对于容器的宽度,而不是高度;
对于一些表示竖向距离的属性,
例如 padding-top
, padding-bottom
, margin-top
, margin-bottom
等,
当按百分比设定它们时,依据的也是父容器的宽度,而不是高度。
# 有一个高度自适应的div,里面有两个div,一个高度100px,希望另一个填满剩下的高度。
<div class="outer">
<div class="a"></div>
<div class="b"></div>
</div>
1
2
3
4
2
3
4
* {
margin: 0;
padding: 0;
}
body {
height: 100%;
}
.out {
position: relative;
height: 100%;
}
.a {
width: 100%;
height: 100px;
background-color: red;
}
.b {
position: absolute;
left: 0;
top: 100px;
bottom: 0;
width: 100%;
background-color: pink;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# 如果需要⼿动写动画,你认为最⼩时间间隔是多久,为什么?
多数显示器默认频率是 60Hz ,即 1 秒刷新 60 次,所以理论上最小间隔为
1⁄60*1000ms = 16.7ms