盒子大小
- 盒子大小
-盒子的计算工式;width/height +padding2+borde r2
宽度: 200 +102 + 22 =224px
高度:150 +102 +22=174px
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css01.css">
</head>
<body>
<div class="box"></div>
</body>
</html>
:root {
font-size: 10px;
}
.box {
width: 20em;
height: 15em;
background-color: crimson;
margin: auto;
}
.box{
padding: 1em;
border: 2px solid;
}
- ie盒子
:root {
font-size: 10px;
}
.box {
width: 20em;
height: 15em;
background-color: crimson;
margin: auto;
}
.box {
padding: 1em;
border: 2px solid;
}
/* 长是20em,宽15 */
.box {box-sizing: content-box;
box-sizing: border-box;
}
场合使用盒子样式(直接粘贴使用)
*{
margin: 0;
padding: 0;
box-sizing: border-box;
}
- 元素过大隐藏与使用滚动条
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css01.css">
</head>
<body>
<div class="box">抗震8度以下:
地下室钢筋含量:75~100KG/㎡;地下室混凝土含量0.52~0.58m3/㎡;
主体钢筋含量:38~45KG/㎡;主体混凝土含量0.4~0.43m3/㎡;主体模板含量:2.4~2.7㎡/㎡。
抗震8度以上地区的高层建筑,在上述基础上,钢筋、混凝土、模板含量增加约30%。</div>
</body>
</html>
:root {
font-size: 10px;
}
.box {
width: 10em;
height: 15em;
border: 1px solid#000;
/* 隐藏内容 */
overflow: hidden;
/* 使用滚动条 */
/* overflow: scroll; */
overflow: auto;
}
- 最小高度的设置,框会自动扩大,缩小
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css01.css">
</head>
<body>
<div>截至202011月php占有率80%</div>
<div>
截至202011月php占有率80% <br>
截至202011月php占有率80% <br>
截至202011月php占有率80% <br>
截至202011月php占有率80% <br>
截至202011月php占有率80% <br>
截至202011月php占有率80% <br>
</div>
</body>
</html>
body>*{
margin: 1em;
}
body div{
border: 1px solid#000;
height: auto;
}
body div:first-of-type{
border: 1px solid#000;
height: auto;
}
body div:nth-of-type(2){
min-height: 5em;
}
body>*{
margin: 1em;
}
body div{
border: 1px solid#000;
height: auto;
}
body div:first-of-type{
border: 1px solid#000;
height: auto;
}
body div:nth-of-type(2){
min-height: 5em;
}
- 块元素水平居中( 常用
margin:0 auto
)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css01.css">
</head>
<body>
<div class="box">
<img src="img/01.png" alt="">
</div>
</div>
</body>
</html>
.box {
width: 15em;
height: 15em;
border: 1px solid#000;
}
.box{
text-align: center;
}
常用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css01.css">
</head>
<body>
<div class="box">
<!-- <img src="img/01.png" alt=""> -->
<div></div>
</div>
</div>
</body>
</html>
.box>div{
width: 5em;
height: 5em;
background-color: blanchedalmond;
}
.box>div{
margin:0 auto;
}
- 垂直居中 padding
.box>div{
width: 5em;
/* height: 5em; */
background-color: blanchedalmond;
}
.box>div{
margin:0 auto;
padding: 5em 0;
}
- 水平垂直居中
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="css01.css">
</head>
<body>
<div class="box">
<a href="">php0cn</a>
</div>
</div>
</body>
</html>
.box{
width: 15em;
height: 15em;
background-color: blanchedalmond;
text-align: center;
line-height: 15em;
}
.box{
width: auto;
height: auto;
padding: 5em;
}