html,body{
margin:0;
padding:0;
}
div:first-child{
width:100%;
height:100%;
background:red;
}
如果这样写的话div的height:100%;是无效的,需要在html,body中加入 height:100%:或者div:first-child中加入position:absolute;div中的height:100%;才有效
如果不在前面声明<!DOCTYPE html>的话两个都不写也行
实现品字形布局代码
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>品字形布局</title>
</head>
<style>
html,body{
margin:0;
padding:0;
height:100%;
}
div:first-child{
/*position:absolute; 两者二选一,*/
width:100%;
height:calc(100% - 200px);
background:red;
}
div:nth-child(2){
position:fixed;
width:50%;
height:200px;
background:green;
bottom:0;
left:0;
}
div:nth-child(3){
position:fixed;
width:50%;
height:200px;
background:yellow;
bottom:0;
right:0;
}
</style>
<body>
<div></div>
<div><