1. CSS3.0弹性布局flex, 无需知道父子元素宽高
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>弹性布局flex, 无需知道父子元素宽高</title>
<style>
html,
body {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
body {
display: flex;
align-items: center;
/*定义body的子元素垂直居中*/
justify-content: center;
/*定义body的子元素水平居中*/
}
.content {
width: 300px;
height: 300px;
background: orange;
}
</style>
</head>
<body>
<div class="content"></div>
</body>
</html>
2.