fixed定位
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
html,body {
height: 100%;
}
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
#root {
padding: 64px 0 0 200px;
height: 100%;
}
header {
position: fixed;
top:0;
left:0;
height: 64px;
border: 1px solid red;
width: 100%;
background: blue;
z-index: 999;
}
nav {
position: fixed;
z-index: 998;
top:0;
left:0;
width: 200px;
border: 1px solid red;
height: 100%;
background: grey;
padding-top: 64px;
}
main {
background: pink;
height: 100%;
}
</style>
</head>
<body>
<div id='root'>
<header>header</header>
<nav>nav</nav>
<main>main</main>
</div>
</body>
</html>
flex定位
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
html,body,#root {
height: 100%;
}
* {
margin: 0;
padding: 0;
}
#root {
display: flex;
flex-direction: column;
}
header {
height: 64px;
background: blue;
}
.container {
flex: 1;
display: flex;
flex-direction: row;
}
nav {
width: 200px;
background: grey;
}
main {
flex: 1;
background: pink;
}
</style>
</head>
<body>
<div id="root">
<header>header</header>
<div class="container">
<nav>nav</nav>
<main>main</main>
</div>
</div>
</body>
</html>
栅格布局
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
html,body,#root {
height: 100%;
}
* {
margin: 0;
padding: 0;
}
#root {
}
nav {
width: 16%;
height: 100%;
float: left;
background: grey;
}
main {
width: 84%;
height: 100%;
float: left;
background: pink;
}
</style>
</head>
<body>
<div id="root">
<nav>nav</nav>
<main>main</main>
</div>
</body>
</html>