圣杯布局
前端面试笔试常问,前端必学经典布局
实现一
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
box-sizing: border-box;
}
.container {
width: 1200px;
margin: 0 auto;
}
.header {
height: 60px;
width: 100%;
background-color: bisque;
}
.footer {
height: 80px;
width: 100%;
background-color: burlywood;
}
.main {
width: 100%;
height: 550px;
background-color: pink;
}
.left {
float: left;
width: 200px;
height: 100%;
background-color: cadetblue;
}
.right {
float: right;
width: 200px;
height: 100%;
background-color: rgb(151, 57, 14);
}
.center {
height: 100%;
margin: 0 200px;
background-color: darkmagenta;
}
</style>
</head>
<body>
<div class="container">
<header class="header"></header>
<div class="main">
<div class="left"></div>
<div class="right"></div>
<!-- 先写左右浮动在前,不然center区域会作为块级顶在前面 -->
<div class="center">fajkfgafjgoafoafgaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
</div>
<footer class="footer"></footer>
</div>
</body>
</html>
实现二
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
* {
box-sizing: border-box;
}
.container {
width: 1200px;
margin: 0 auto;
}
.header {
height: 60px;
width: 100%;
background-color: bisque;
}
.footer {
height: 80px;
width: 100%;
background-color: burlywood;
}
.main {
display: flex;
width: 100%;
height: 550px;
background-color: pink;
}
.left {
width: 200px;
height: 100%;
background-color: cadetblue;
}
.right {
width: 200px;
height: 100%;
background-color: rgb(151, 57, 14);
}
.center {
flex: 1;
height: 100%;
background-color: darkmagenta;
}
</style>
</head>
<body>
<div class="container">
<header class="header"></header>
<div class="main">
<div class="left"></div>
<!--
flex 布局讲究顺序
-->
<div class="center">fajkfgafjgoafoafgaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa</div>
<div class="right"></div>
</div>
<footer class="footer"></footer>
</div>
</body>
</html>
Some birds are not meant to be caged, their feathers are just too bright.
有些鸟儿注定不会被困于牢笼,它们的每片羽毛都闪耀着自由的光辉。
本人菜鸟,如有不足,请评论区多多指教
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/64484.html