关于“品”字布局的问题(百分比高度设置出现的问题)

关于百分比设置高度一个案例,品字布局注意的问题,<!DOCTYPE> 声明不是 HTML 标签;它是指示 web 浏览器关于页面使用哪个 HTML 版本进行编写的指令。
这里如果用<!DOCTYPE html>则元素的高度无效,总是为零。
<!DOCTYPE>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>

</head>
<style>
* {
margin: 0;
padding: 0;
}

.div1 {
100%;
height: 50%;
background-color: red;
}

.div2 {
100%;
height: 50%
}

.div2 div {
float: left;
50%;
height: 100%
}

.div2 div:nth-child(1) {
background-color: dodgerblue
}

.div2 div:nth-child(2) {
background-color: yellow
}
</style>
<body>
<div class="div1"></div>
<div class="div2">
<div></div>
<div></div>
</div>
</body>
</html>
原文地址:https://www.cnblogs.com/dujishi/p/5711384.html