簡單實現(xiàn)柵格布局的兩種方式
發(fā)布時間:2015-03-10 10:01:46 作者:佚名
我要評論

本文給大家介紹的是2種柵格布局的簡單實現(xiàn)方式,并附上示例代碼,非常實用,這里推薦給大家,有需要的小伙伴參考下吧。
一、使用float:
復(fù)制代碼
代碼如下:<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style>
section
{
border: solid 1px;
}
section section
{
float: left;
margin-left: 10px;
margin-top: 10px;
text-align: center;
width: 200px;
border-radius: 20px;
height: 200px;
}
.parent
{
height: 440px;
width: 660px;
}
.parent section:first-child
{
height: 410px;
}
</style>
</head>
<body>
<section class="parent">
<section>A</section>
<section>B</section>
<section>C</section>
<section>D</section>
<section>E</section>
</section>
</body>
</html>
二、使用display:flex(這個css3屬性僅谷歌和火狐支持)
復(fù)制代碼
代碼如下:<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<style>
section
{
border: solid 1px;
}
section section
{
margin-left: 10px;
margin-top: 10px;
text-align: center;
width: 200px;
border-radius: 20px;
height: 200px;
}
.parent
{
display: flex;
flex-direction: column;
flex-wrap: wrap;
height: 440px;
width: 660px;
}
.parent section:first-child
{
height: 410px;
}
</style>
</head>
<body>
<section class="parent">
<section>A</section>
<section>B</section>
<section>C</section>
<section>D</section>
<section>E</section>
</section>
</body>
</html>
實現(xiàn)效果如圖所示:
當(dāng)然使用table和負邊距也是可以實現(xiàn)的,有時間補上:-D
以上就是本文所述的全部內(nèi)容了,希望大家能夠喜歡。
相關(guān)文章
bootstrap3.0教程之柵格系統(tǒng)原理(布局)
Bootstrap內(nèi)置了一套響應(yīng)式、移動設(shè)備優(yōu)先的流式柵格系統(tǒng),隨著屏幕設(shè)備或視口(viewport)尺寸的增加,系統(tǒng)會自動分為最多12列。我在這里是把Bootstrap中的柵格系統(tǒng)叫做布2014-04-11bootstrap3.0教程之柵格系統(tǒng)案例(包括柵格選項、從堆疊到水平排列、移
這篇文章主要介紹了bootstrap3.0教程之柵格系統(tǒng)案例,包括柵格選項、從堆疊到水平排列、移動設(shè)備和桌面、Responsive column resets、列偏移、嵌套列、列排序,需要的朋友可以2014-04-11