CSS两列合理布局完成方式大全

2021-01-20 07:53 jianzhan

引言:
  两列合理布局在网站运用中也是常常见到的,今日就共享4中两列合理布局。

display:table


拷贝编码
编码以下:

<style>
.table {
width: auto;
min-width: 1000px;
margin: 0 auto;
padding: 0;
display:table;
}
.tableRow {
display: table-row;
}
.tableCell {
border: 1px solid red;
display: table-cell;
width: 33%;
}
</style>
<div class="table" >
<div class="tableRow" >
<div class="tableCell" >
one
</div>
<div class="tableCell" >
two
</div>
<div class="tableCell" >
three
</div>
</div>
</div>

float


拷贝编码
编码以下:

<style>
.row {
float: left;
width: 33%;
border: 1px solid red;
}
</style>
<div class="row" >
one
</div>
<div class="row" >
two
</div>
<div class="row" >
three
</div>

display: inline-block


拷贝编码
编码以下:

<style>
.row {
display: inline-block;
width: 32%;
border: 1px solid red;
}
</style>
<div class="row" >
one
</div>
<div class="row" >
two
</div>
<div class="row" >
three
</div>

column-count


拷贝编码
编码以下:

<style>
.column {
/* 设定列数 */
-moz-column-count:3; /* Firefox */
-webkit-column-count:3; /* Safari and Chrome */
column-count:3;
/* 设定列之间的间隔 */
-moz-column-gap:40px; /* Firefox */
-webkit-column-gap:40px; /* Safari and Chrome */
column-gap:40px;
/* 设定列之间的标准 */
-moz-column-rule:4px outset #ff0000; /* Firefox */
-webkit-column-rule:4px outset #ff0000; /* Safari and Chrome */
column-rule:4px outset #ff0000;
}
</style>
<div class="column"></div>

小结:
  以上编码全是在chrome上检测,假如应用请留意适配性,有任何难题都可以以发问