面:请用至少三种方式实现三栏布局.
我:好.
方式一:float方式
<html>
<head>
<meta charset="UTF-8">
<title>左右固定,中间自适应</title>
<style>
.txtCenter{
text-align: center;
line-height: 200px;
font-size:20px;
color:#fff;
}
.parentDiv{
height:200px;
}
.leftDiv{
float:left;
width:200px;
height:200px;
background-color: #5A6A94;
}
.rightDiv{
float:right;
width:200px;
height:200px;
background-color: #EA6F5A;
}
.centerDiv{
height:200px;
margin-left:210px;
margin-right:210px;
background-color: #FFD5B1;
}
</style>
</head>
<body>
<div class="parentDiv">
<div class="leftDiv txtCenter">Left</div>
<div class="rightDiv txtCenter">Right</div>
<div class="centerDiv txtCenter">Center</div>
</div>
</body>
</html>
方式二:圣杯布局
<html>
<head>
<meta charset="UTF-8">
<title>左右固定,中间自适应</title>
<style>
.txtCenter{
text-align: center;
line-height: 200px;
font-size:20px;
color:#fff;
}
.parentDiv{
padding-left:210px;
padding-right:210px;
height:200px;
}
.leftDiv{
float: left;
margin-left:-100%;
position: relative;
left:-210px;
width:200px;
height:200px;
background-color: #5A6A94;
}
.rightDiv{
float: left;
margin-left:-200px;
position: relative;
right:-210px;
width: 200px;
height: 200px;
background-color: #EA6F5A;
}
.centerDiv{
float:left;
width:100%;
height:200px;
background-color: #FFD5B1;
}
</style>
</head>
<body>
<div class="parentDiv">
<div class="centerDiv txtCenter">Center</div>
<div class="leftDiv txtCenter">Left</div>
<div class="rightDiv txtCenter">Right</div>
</div>
</body>
</html>
方式三:flex方式
<html>
<head>
<meta charset="UTF-8">
<title>左右固定,中间自适应</title>
<style>
.txtCenter{
text-align: center;
line-height: 200px;
font-size:20px;
color:#fff;
}
.parentDiv{
display: flex;
flex-direction: row;
}
.leftDiv{
width:200px;
height: 200px;
order: -1;
margin-right: 10px;
flex: 0 1 200px;
background-color: #5A6A94;
}
.rightDiv{
height: 200px;
margin-left: 10px;
flex: 0 1 200px;
background-color: #EA6F5A;
}
.centerDiv{
height: 200px;
background-color: #FFD5B1;
flex-grow: 1;
}
</style>
</head>
<body>
<div class="parentDiv">
<div class="centerDiv txtCenter">Center</div>
<div class="leftDiv txtCenter">Left</div>
<div class="rightDiv txtCenter">Right</div>
</div>
</body>
</html>
面:你还能想到其它的实现方式吗?
我:是的.
面:请口述一下.
我:双飞翼布局,绝对定位布局.
面:能说下圣杯布局和双飞翼布局的区别吗?
我:中间主体内容的处理方式不同.
面:怎么不同?
我:额 我还是写一下吧
面:可以.
方式四:双飞翼布局
<html>
<head>
<meta charset="UTF-8">
<title>左右固定,中间自适应</title>
<style>
.txtCenter{
text-align: center;
line-height: 200px;
font-size:20px;
color:#fff;
}
.parentDiv{
float: left;
width: 100%;
}
.leftDiv{
float: left;
margin-left: -100%;
width:200px;
height: 200px;
background-color: #5A6A94;
}
.rightDiv{
width: 200px;
height: 200px;
float: left;
margin-left: -200px;
background-color: #EA6F5A;
}
.centerDiv{
margin-left: 210px;
margin-right: 210px;
height: 200px;
background-color: #FFD5B1;
}
</style>
</head>
<body>
<div style="overflow:hidden;">
<div class="parentDiv">
<div class="centerDiv txtCenter">Center</div>
</div>
<div class="leftDiv txtCenter">Left</div>
<div class="rightDiv txtCenter">Right</div>
</div>
</body>
</html>
面:你怎么在外层写了一个Div并且写了overflow了呢?
我:为了不影响其它因素.
面:写清除浮动不行吗!为什么要这样写?
我:额 也可以的,我自己喜欢这么干,自己设置了float,影响了别人,还要让别人擦屁股?.
面:额 我们继续下一题.
我:好.