前端 布局方式 及 实例

1、右列定宽,左列自适应

html布局:
	<div class ="parent">
		<div class ="left"> </div>
		<div class ="right"> </div>
	</div>
样式设置;	
1.使用float+margin实现。
	.parent{
		background: red;
		height:100px;
		margin:0 auto;
	}
	.left{
		background:green;
		margin-right:-100px;
		width:100%;
		float:left;
	}
	.right{
		float:right;
		width:100px;
		background:blue;
	}
2.使用table实现
	.parent{
		display:table;
		table-layout:fixed;
		width:100%;
	}
	.left{
		 display:table-cell;
	 }
	 .right{
		  width:100px;
		  display:table-cell;
	  }
3.使用flex实现
	.parent{
		display:flex; 
	}	  
	.left{
		 flex:1;
	 }
	 .right{
		width:100px;
	}

2、两侧定宽,中栏自适应

1.利用float+margin实现
	.left{
		 height:100px
		 background:red;
		 width:100px;
		 float:left;
	 }
	 .center{
		height:100px
		background:green;
		float:left;
		width:100%;
		margin-right:-200px;	
	}
	.right{
		height:100px
		background:blue;
		width:100px;
		float:right;
	 }

3、九宫格布局

html部分	
<div class="parent">
	<div class="row">
		<div class="item "></div>
		<div class="item "></div>
		<div class="item three"></div>
	</div>
	<div class="row">
		<div class="item "></div>
		<div class="item "></div>
		<div class="item three"></div>
	</div>
	<div class="row">
		<div class="item one"></div>
		<div class="item two"></div>
		<div class="item three four"></div>
	</div>
</div>
		 
样式部分:
1.使用table实现
.parent{
	background: red;
	display:table;
	table-layout: fixed;
	width: 100%;
}
.row{

	display: table-row;
}			
.item{
	border: 1px solid gray;
	display: table-cell;
	width: 33.3%;
	height: 200px;
}		 
2.使用flex实现
	
.parent{
	display: flex;
	flex-direction: column;
}
.row{
	height: 100px;
	display: flex;
}
.item{
	border-left: 1px solid gray;
	border-top: 1px solid gray;
	width: 100px;
	background: red;
}		
.three{
	border-right: 1px solid gray;
}
.one{
	border-bottom: 1px solid gray;
}
.two{
	border-bottom:1px solid gray ;
}
.four{
	border-bottom: 1px solid gray;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值