码迷,mamicode.com
首页 > 其他好文 > 详细

解决 等分 布局

时间:2015-10-23 01:32:02      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:

等分布局

每一列的间距一样,


(1)用浮动比较复杂。float
<div class="parent">
	<div class="column"> <p class=‘content‘>1</p> </div>
	<div class="column"> <p class=‘content‘>2</p> </div>
	<div class="column"> <p class=‘content‘>3</p> </div>
	<div class="column"> <p class=‘content‘>4</p> </div>
	<div class="column"> <p class=‘content‘>5</p> </div>
</div>


<style type="text/css">
	body {
		margin: 0;
		padding: 0;
	}

	.parent {
		margin-left: -20px;
		background-color: #ddd;
	}
	.content {
		background-color: #999;
	}
	.column {
		float: left;
		width: 20%;
		padding-left: 20px;
		box-sizing : border-box;
		background-color: #369;
	}

</style>

(2)table
缺点就是多了一行div

<div class="parent-fix">
	<div class="parent">
		<div class="column"> <p class=‘content‘>1</p> </div>
		<div class="column"> <p class=‘content‘>2</p> </div>
		<div class="column"> <p class=‘content‘>3</p> </div>
		<div class="column"> <p class=‘content‘>4</p> </div>
		<div class="column"> <p class=‘content‘>5</p> </div>
	</div>
</div>
<style type="text/css">
	body {
		margin: 0;
		padding: 0;
	}

	.parent-fix {
		margin-left: -20px;
	}

	.parent {
		display: table;
		width: 100%;
		table-layout: fixed;	/*布局优先,平分单元格。*/
	}
	.content {
		background-color: #999;
	}
	.column {
		display: table-cell;
		padding-left: 20px;
		background-color: #369;
	}

</style>


(3)一直以来最强大的布局方式 flex
缺点就是兼容性问题
<div class="parent"> <div class="column"> <p class=‘content‘>1</p> </div> <div class="column"> <p class=‘content‘>2</p> </div> <div class="column"> <p class=‘content‘>3</p> </div> <div class="column"> <p class=‘content‘>4</p> </div> <div class="column"> <p class=‘content‘>5</p> </div> </div> <style type="text/css"> body { margin: 0; padding: 0; } .parent { display: flex; table-layout: fixed; background-color: #ddd; } .content { background-color: #999; } .column { flex: 1; background-color: #369; } .column+.column { margin-left: 20px; } </style>

  

解决 等分 布局

标签:

原文地址:http://www.cnblogs.com/hgonlywj/p/4903259.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!