<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Layout</title>
<style media="screen">
html *{
padding: 0;
margin: 0;
}
.layout article div{
min-height: 100px;
}
</style>
</head>
<body>
<!-- 浮动布局 -->
<section class="layout float">
<style media="screen">
.layout.float .left {
width: 200px;
background-color: aqua;
float: left;
}
.layout.float .right {
width: 200px;
background-color: aqua;
float: right;
}
.layout.float .center {
background-color: yellow;
}
</style>
<h1>浮动布局</h1>
<article class="left-center-right">
<div class="left"></div>
<div class="right"></div>
<div class="center">
<h1>浮动定位解决方案</h1>
1.这是三栏布局中浮动定位中间部分
</div>
</article>
</section>
<!-- 绝对定位 -->
<section class="layout absolute">
<style media="screen">
.layout.absolute {
height: 133px;
}
.layout.absolute .left-center-right>div {
position: absolute;
}
.layout.absolute .left {
width: 200px;
background-color: aqua;
left: 0;
}
.layout.absolute .center {
background-color: yellow;
left: 200px;
right: 200px;
}
.layout.absolute .right {
width: 200px;
background-color: aqua;
right: 0;
}
</style>
<h1>绝对定位</h1>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h1>绝对定位解决方案</h1>
1.这是三栏布局中绝对定位中间部分
</div>
<div class="right"></div>
</article>
</section>
<!-- flex布局 -->
<section class="layout flex">
<style>
.layout.flex .left-center-right {
display: flex;
}
.layout.flex .left {
width: 200px;
background-color: aqua;
}
.layout.flex .right {
width: 200px;
background-color: aqua;
}
.layout.flex .center {
flex: 1;
background-color: yellow;
}
</style>
<h1>flex 布局</h1>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h1>flex布局解决方案</h1>
1.这是三栏布局中 flex 布局中间部分
</div>
<div class="right"></div>
</article>
</section>
<!-- table cell 布局解决方案 -->
<section class="layout tablecell">
<style>
.layout.tablecell .left-center-right {
width: 100%;
height: 100px;
display: table;
}
.layout.tablecell .left-center-right>div {
display: table-cell;
}
.layout.tablecell .left {
width: 200px;
background-color: aqua;
}
.layout.tablecell .right {
width: 200px;
background-color: aqua;
}
.layout.tablecell .center {
background-color: yellow;
}
</style>
<h1>table cell 布局</h1>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h1>table cell 布局解决方案</h1>
1.这是三栏布局中 table cell 布局中间部分
</div>
<div class="right"></div>
</article>
</section>
<!-- grid 布局解决方案 -->
<section class="layout grid">
<style>
.layout.grid .left-center-right{
width: 100%;
display: grid;
grid-template-rows: 100px;
grid-template-columns: 200px auto 200px;
}
.layout.grid .left {
background-color: aqua;
}
.layout.grid .center {
background-color: yellow;
}
.layout.grid .right {
background-color: aqua;
}
</style>
<h1>grid 布局解决方案</h1>
<article class="left-center-right">
<div class="left"></div>
<div class="center">
<h1>grid 布局解决方案</h1>
1.这是三栏布局中 grid 布局中间部分
</div>
<div class="right"></div>
</article>
</section>
</body>
</html>
网友评论