1. 引用下曹刘阳写的《编写高质量代码-web前端开发修炼之道》一书中看到的一句话:
position:absolute和float会隐式地改变display类型,不论之前什么类型的元素(display:none除外),
只要设置了position:absolute、 float中任意一个,都会让元素以display:inline-block的方式显示:可以设置长宽,默认宽度并不占满父元素
以span为例子,如何让元素变为inline-block。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
</head>
<body>
<span style="height:100px;width:200px;background:yellowgreen">normal span, width and height doesn't work.</span>
<br>
<br>
<span style="height:100px;width:200px;background:pink;position:absolute">span with position:absolute, width and
height work.</span>
<br>
<br>
<br>
<br>
<br>
<span style="height:100px;width:200px;background:orange;float:left">span with float:left, width and height
work.</span>
<br>
<br>
<br>
<br>
<br>
<div style="display: flex">
<span style="height:100px;width:200px;background:gold;">span's father with display:flex, width and height
work.</span>
</div>
<br>
<span style="height:100px;width:200px;background:deeppink;position:fixed">span with position:fixed, width and height
work.</span>
</body>
</html>
2. Fixed未解之谜
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
body{
margin: 0;
padding: 0;
}
.box1{
width: 100%;
position: fixed;
height:80px;
background: yellowgreen;
}
p{
margin:30px;
}
</style>
</head>
<body>
<div class="box1"></div>
<p>Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin
literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney
College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and
going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum
comes from sections 1.10.32 and 1.10.33 of "de Finibus Bonorum et Malorum" (The Extremes of Good and Evil) by
Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance.
The first line of Lorem Ipsum, "Lorem ipsum dolor sit amet..", comes from a line in section 1.10.32.
The standard chunk of Lorem Ipsum used since the 1500s is reproduced below for those interested. Sections
1.10.32 and 1.10.33 from "de Finibus Bonorum et Malorum" by Cicero are also reproduced in their exact original
form, accompanied by English versions from the 1914 translation by H. Rackham.</p>
<p style="color:red">去掉段落,box1没有top margin, 加上段落后,就会出现top margin,margin来自于p的margin Why</p>
<p>生成绝对定位的元素,相对于浏览器窗口进行定位。这不对啊</p>
</body>
</html>
3. background-size 详述
contain:自由伸展,直到有一边贴边。 包含,但是会有富裕
cover: 等比例覆盖,没有空白,图片会有显示不到的地方。
percentage: X% Y% 宽高均参考父元素。
length:具体数值。只给一个值,另外一个值为auto, 50% (auto), auto 50%, background-size默认情况是(auto auto),使用图片自己本身的尺寸。
4. background 的image居中 可以使用background-position:50% 50%
5. 设置多个相同元素间隔,可以使用margin-left/right