一、静态布局
概况:给页面元素设置固定的宽度和高度,单位用px,当窗口缩小,会出现滚动条,拉动滚动条显示被遮挡内容。针对不同分辨率的手机端,分别写不同的样式文件。
(1)一栏布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
html,body{
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
.header{
height: 30%;
background: red;
}
.content{
height: 30%;
background: skyblue;
}
.footer{
height: 40%;
background:yellow;
}
</style>
</head>
<body>
<div class="header"></div>
<div class="content"></div>
<div class="footer"></div>
</body>
</html>
运行结果如下:浏览器全屏
(2)两栏布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box{
margin: auto;
width: 500px;
height: 500px;
background: pink;
}
.top{
width: 200px;
height: 300px;
float: left;
background: yellowgreen;
}
.footer{
float: right;
width: 200px;
height: 300px;
background: red;
}
</style>
</head>
<body>
<div class="box">
<div class="top"></div>
<div class="footer"></div>
</div>
</body>
</html>
运行结果如下
(3)固定宽度布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
html,body{
margin: 0;
padding: 0;
}
.box{