Correcting teacher:Guanhui
Correction status:qualified
Teacher's comments:写的很好!flex是页面布局的一大利器,另外有的代码没有用代码块框起来,注意一下!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>基于浮动的二列布局</title>
<style>
header,
footer,
aside,
main{
background-color: cornflowerblue;
}
header,
footer{
height: 50px;
}
aside,
main{
min-height: 400px;
}
.wrap{
width: 1000px;
border: 1px solid #000;
overflow: hidden;
margin: 10px auto;
}
aside{
width: 200px;
float: left;
}
main{
width: 790px;
float: right;
}
</style>
</head>
<body>
<h2>NO1.基于浮动的二列布局</h2>
<header>页眉</header>
<div class="wrap">
<aside>侧边栏</aside>
<main>主体区</main>
</div>
<footer>页脚</footer>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>基于定位的二列布局</title>
<style>
header,
footer,
aside,
main{
background-color: cornflowerblue;
}
header,
footer{
height: 50px;
}
.wrap{
width: 1000px;
min-height:500px;
border: 1px solid #000;
margin: 10px auto;
/* 定位父级 */
position: relative;
}
aside{
width: 200px;
min-height: inherit;
position: absolute;
top:0;
left:0;
}
main{
width: 790px;
min-height: inherit;
background-color:lightblue;
position: absolute;
top:0;
right:0;
}
</style>
</head>
<body>
<h2>NO2.基于定位的二列布局</h2>
<header>页眉</header>
<div class="wrap">
<aside>侧边栏</aside>
<main>主体区</main>
</div>
<footer>页脚</footer>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>内容的多栏显示</title>
<style>
初始化
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
:root {
font-size: 16px;
color: lightsalmon;
}
div{
border:1px solid lightblue;
padding: 1rem;
width: 60rem;
margin:10px auto;
}
div{
/* 分列显示 */
column-count:3;
/* column-rule-style:solid; */
/* column-rule-width: 1px; */
/* column-rule-color: red; */
column-rule:1px solid red;
}
header{
color:blue;
font-size: 1.3rem;
}
</style>
</head>
<body>
<header>NO3.内容的多栏显示</header>
<div>
【环球网报道】《港区国安法》正式生效后,香港特区维护国家安全委员会及警务处国家安全处随即成立。香港《东方日报》3日消息称,香港保安局局长李家超表示,国安处要面对国家级对手,故由副处长领导,职级是警队六处中最高,凸显其重要地位。李家超透露,一旦处理涉及危害国家安全的恐怖主义活动,国安处可动用其他部门配合,包括“飞虎队”及拆弹专家等,保安局则负责统筹及协调政府各部门及各纪律部队的国安工作,包括海关及入境处,严防危险品及目标人物进入香港。
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>三列布局</title>
<style>
header,
footer{
height: 40px;
background-color: lightsalmon;
}
.container{
width: 1000px;
margin:10px atuo;
border:1px solid red;
/* 分为三列 */
column-count: 3;
}
aside{
background-color: lightseagreen;
min-height: 600px;
}
main{
background-color: limegreen;
min-height: 600px;
}
main{
column-span:2;
min-height: 600px;
}
</style>
</head>
<body>
<h2>NO4.三列布局</h2>
<header>header</header>
<div class="container">
<aside>left</aside>
<main>main</main>
<aside>right</aside>
</div>
<footer>footer</footer>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>flexbox弹性盒子布局快速预览</title>
<style>
.container{
width: 300px;
/* 如果这个容器中的内容要使用lexbox布局,第一步就是必须将此容器转为弹性盒子 */
/* 弹性容器 */
display: flex;
}
.container > .item{
/* 一旦将父元素转为弹性容器,内部的子元素会自动成为弹性项目 */
/* 不管这个项目标签是什么类型,统统转为“行内块” */
/* 行内:全部一排显示 */
/* 块:可以摄制组宽,高 */
/* flex:auto; */
/* width: 60px; */
/* width: 50; */
width:120px;
}
/* 换行显示 ,多行元素*/
.container{
flex-wrap: wrap;
}
/* 主轴,交叉轴(又名侧轴,列轴,辅助轴) */
</style>
</head>
<body>
<h5>NO5.flexbox弹性盒子布局快速预览</h5>
<div class="container">
<div class="item">1</div>
<span class="item" >2</span>
<a class="item">3</a>
<a class="item">4</a>
<a class="item">5</a>
</div>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>flexbox弹性盒子多行容器</title>
<style>
.container{
width: 300px;
/* 如果这个容器中的内容要使用lexbox布局,第一步就是必须将此容器转为弹性盒子 */
/* 弹性容器 */
display: flex;
}
.container > .item{
/* 一旦将父元素转为弹性容器,内部的子元素会自动成为弹性项目 */
/* 不管这个项目标签是什么类型,统统转为“行内块” */
/* 行内:全部一排显示 */
/* 块:可以摄制组宽,高 */
/* flex:auto; */
/* width: 60px; */
/* width: 50; */
width:120px;
}
/* 换行显示 ,多行元素*/
/* 显示,火狐页面右键-查看元素-查看器-flex */
.container{
flex-wrap: wrap;
}
/* 主轴,交叉轴(又名侧轴,列轴,辅助轴) */
</style>
</head>
<body>
<h5>NO6.flexbox弹性盒子多行容器</h5>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
<div class="item">5</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">
<title>单行容器中的项目对齐方式</title>
<style>
.container {
width: 300px;
/* 显示,火狐页面右键-查看元素-查看器-flex */
display: flex;
/* justify-content: 控制所有项目在主轴上的对齐方式; */
/* 本质是:设置容器中的剩余空间在所有“项目之间”的分配方案 */
/* 1.容器剩余空间在所有项目“二边”的如何分配,将全部项目视为一个整体 */
justify-content: flex-start;
justify-content: flex-end;
justify-content: center;
/* 2.容器剩余空间在所有项目“之间”的如何分配 ,将项目视为一个个独立的个体*/
/* 两端对齐: */
justify-content: space-between;
/* 分散对齐:剩余空间在所有项目的两侧平均分配,中间间距是两端间距的2倍*/
justify-content: space-around;
/* 所有项目平均分配,空间数=项目数+1 */
justify-content: space-evenly;
}
.container > .item{
width: 60px;
}
</style>
</head>
<body>
<h5>NO.7 单行容器中的项目对齐方式</h5>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</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">
<title>多行容器中的项目对齐方式</title>
<style>
.container {
width: 300px;
/* 显示,火狐页面右键-查看元素-查看器-flex */
display: flex;
/* 多行显示 */
flex-wrap: wrap;
height: 120px;
/* align-content: 设置多行容器中的项目排列; */
/* 1.容器剩余空间在所有项目“二边”的如何分配,将全部项目视为一个整体 */
align-content:stretch;
align-content: flex-start;
align-content: flex-end;
align-content: center;
/* 2.容器剩余空间在所有项目“之间”的如何分配 ,将项目视为一个个独立的个体*/
align-content: space-between;
align-content: space-around;
align-content: space-evenly;
}
.container > .item{
width: 60px;
}
</style>
</head>
<body>
<h5>NO.8 多行容器中的项目对齐方式</h5>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">11</div>
<div class="item">12</div>
<div class="item">13</div>
<div class="item">21</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">
<title>NO.9 主轴垂直时的项目排列</title>
<style>
.container {
width: 300px;
height: 150px;
/* 显示,火狐页面右键-查看元素-查看器-flex */
display: flex;
/* 主轴的方向,默认为行 */
flex-direction: row;
/* 主轴的方向为列 */
flex-direction: column;
/* 项目两边分配 */
justify-content: space-between;
justify-content: space-around;
justify-content: space-evenly;
/* 项目之间分配 */
/* align-content: space-between; */
/* align-content: space-around; */
align-content: space-evenly;
}
</style>
</head>
<body>
<h5>NO.9 主轴垂直时的项目排列</h5>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</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">
<title>NO10.交叉轴的项目排列</title>
<style>
.container {
width: 300px;
height: 150px;
display:flex;
/* 项目在交叉轴上是自动伸缩的 */
align-items:stretch ;
align-items:normal;
align-items:flex-start;
align-items:flex-end;
align-items:center;
}
.container > .item{
width: 60px;
}
</style>
</head>
<body>
<h5>NO10.交叉轴的项目排列</h5>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</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">
<title>NO11.主轴方向与项目排列的简写</title>
<style>
.container {
width: 300px;
height: 50px;
display:flex;
/* 默认值,不用写出来 */
/* flex-direction: row; */
/* flex-wrap: nowrap; */
/* flex-flow: row nowrap; */
flex-flow: column wrap;
flex-flow: column nowrap;
}
.container > .item{
width: 60px;
}
</style>
</head>
<body>
<h5>NO11.主轴方向与项目排列的简写</h5>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">1</div>
<div class="item">2</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">
<title>NO12.flex容器属性实战:快速来一个主导航</title>
<style>
*{
padding: 0;
margin: 0;
box-sizing: border-box;
}
a {
text-decoration: none;
color:red;
}
nav{
height: 40px;
background-color: lightblue;
padding: 0 50px;
/* 转为弹性盒布局 */
display:flex;
}
nav a{
height: inherit;
line-height: 40px;
padding: 0 15px;
}
nav a:hover{
background-color: seagreen;
color:white;
}
/* 登录注册放在最右边 */
nav a:last-of-type{
margin-left:auto;
}
</style>
</head>
<body>
<h5>NO12.flex容器属性实战:快速来一个主导航</h5>
<header>
<nav>
<a href="">主页</a>
<a href="">教学视频</a>
<a href="">社区问答</a>
<a href="">资源下载</a>
<a href="">登录/注册</a>
</nav>
</header>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>NO.13 项目属性:order控制项目顺序</title>
<style>
.container {
width: 300px;
display: flex;
}
.container > .item{
width: 60px;
}
.container> .item:last-of-type{
/* order:默认是0 */
order:3;
}
.container> .item:last-of-type{
/* order:默认是0 */
order:6;
}
</style>
</head>
<body>
<h5>NO.13 项目属性:order控制项目顺序</h5>
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</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">
<title>NO.14 order案例:调整元素顺序</title>
<style>
.container {
width: 300px;
display: flex;
flex-direction: column;
/* position: relative; */
}
.container > .item{
border: 1px solid #000;
padding: 10px;
display: flex;
position: relative;
}
.container> .item>div{
display: flex;
}
</style>
</head>
<body>
<h5>NO.14 order案例:调整元素顺序</h5>
<div class="container">
<div class="item">
image-1.jpg
<div>
<button onclick="up(this)">up</button>
<button onclick="down(this)">down</button>
</div>
</div>
<div class="item">
image-2.jpg
<div>
<button onclick="up(this)">up</button>
<button onclick="down(this)">down</button>
</div>
</div>
<div class="item">
image-3.jpg
<div>
<button onclick="up(this)">up</button>
<button onclick="down(this)">down</button>
</div>
</div>
</div>
<script>
let up=(ele)=>(ele.offsetParent.style.order -= 1);
let down= (ele)=>(ele.offsetParent.style.order += 1);
</script>
</body>
</html>