简单实现栅格布局的两种方式

  发布时间:2015-03-10 10:01:46   作者:佚名   我要评论
本文给大家介绍的是2种栅格布局的简单实现方式,并附上示例代码,非常实用,这里推荐给大家,有需要的小伙伴参考下吧。
(福利推荐:【腾讯云】服务器最新限时优惠活动,云服务器1核2G仅99元/年、2核4G仅768元/3年,立即抢购>>>:9i0i.cn/qcloud

(福利推荐:你还在原价购买阿里云服务器?现在阿里云0.8折限时抢购活动来啦!4核8G企业云服务器仅2998元/3年,立即抢购>>>:9i0i.cn/aliyun

一、使用float:


复制代码
代码如下:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<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属性仅谷歌和火狐支持)


复制代码
代码如下:

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gbk" />
<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>

 实现效果如图所示:

当然使用table和负边距也是可以实现的,有时间补上:-D

以上就是本文所述的全部内容了,希望大家能够喜欢。

相关文章

最新评论


http://www.vxiaotou.com