【css】实现圣杯布局的方法(这里列举的是两端固定值,中间自适应)

在这里插入图片描述
方法1:使用flex布局。 中间自适应的部分为:flex:1;

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>圣杯布局</title>
    </head>
<body>

  <div class="wrap">
	<div class="left">left</div>
	<div class="middle">middle</div>
	<div class="right">right</div>
  </div>  
       
<script>
           
</script>

<style>
.wrap{
width:100vw;
height:100vh;
display:flex;
}
 .left{
	width:100px;
	background:red;
	height:100%;
 } 
.right{
 width:100px;
 heigth:100%;
 background:red;
} 
.middle{
  flex:1;
  background:blue;
}
        
</style>
 
</body>
</html>

方法2:使用 浮动定位。calc(100% - 200px);(减号要空两格)

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>圣杯布局</title>
    </head>
<body>

  <div class="wrap">
	<div class="left">left</div>
	<div class="middle">middle</div>
	<div class="right">right</div>
  </div>  
       
<script>
           
</script>

<style>
.wrap{
width:100vw;
height:100vh;
}
 .left{
	width:100px;
	background:red;
	height:100%;
	float:left;
 } 
.right{
 width:100px;
 height:100%;
 background:red;
 float:right;
} 
.middle{
  width:calc(100% - 200px);
  height:100vh;
  float:left;
  background:blue;
  
}
        
</style>
 
</body>
</html>

方法3:使用positon定位。calc(100% - 200px);

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>圣杯布局</title>
    </head>
<body>

  <div class="wrap">
	<div class="left">left</div>
	<div class="middle">middle</div>
	<div class="right">right</div>
  </div>  
       
<script>
           
</script>

<style>
.wrap{
width:100vw;
height:100vh;
}
.left{
	width:100px;
	background:red;
	height:100%;
	position:absolute;
	left:0;
	top:0;
 } 
.right{
 width:100px;
 height:100%;
 background:red;
 position:absolute;
 right:0px;
 top:0px;
} 

.middle{
  width:calc(100% - 200px);
  height:100vh; 
  background:blue;
  position:absolute;
  left:100px;
  top:0px;
  
}
        
</style>
 
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值