码迷,mamicode.com
首页 > Web开发 > 详细

css3六边形平铺

时间:2016-05-19 13:23:48      阅读:182      评论:0      收藏:0      [点我收藏+]

标签:css3

.hex_top_triangle{
    width: 0;
    border-bottom: 30px solid #6C6;
    border-left: 52px solid transparent;
    border-right: 52px solid transparent;
}
.hex_center_rect{
    width: 104px;
    height: 60px;
    background-color: #6C6;
}
.hex_bottom_triangle{
    width: 0;
    border-top: 30px solid #6C6;
    border-left: 52px solid transparent;
    border-right: 52px solid transparent;
}
.float{
    float:left;
    margin-left:1px;
    margin-bottom: -29px;
}
.row_even{
    clear: left;
    margin-left:52px;
   /* margin-top:30px;*/
}
.hex_even{
    float:left;
    margin-left:1px;
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link href="hex.css" type="text/css" rel="stylesheet"/>
<body>
<div>
    <div class="float">
        <div class="hex_top_triangle"></div>
        <div class="hex_center_rect"></div>
        <div class="hex_bottom_triangle"></div>
    </div>
    <div class="float">
        <div class="hex_top_triangle"></div>
        <div class="hex_center_rect"></div>
        <div class="hex_bottom_triangle"></div>
    </div>
    <div class="float">
        <div class="hex_top_triangle"></div>
        <div class="hex_center_rect"></div>
        <div class="hex_bottom_triangle"></div>
    </div>
</div>
<div class="row_even">
    <div class="hex_even">
        <div class="hex_top_triangle"></div>
        <div class="hex_center_rect"></div>
        <div class="hex_bottom_triangle"></div>
    </div>
    <div class="hex_even">
        <div class="hex_top_triangle"></div>
        <div class="hex_center_rect"></div>
        <div class="hex_bottom_triangle"></div>
    </div>
</div>
</body>
</html>

对蜂窝状的排版结构的模仿半成品,从简单的规律演化出缤纷的效果来。深入了对css的理解,可以做出简单的六边形之后难点就变成了,如何将这些简单的六边形排版,我的第一感是将一个六边形放入div中然后通过变形什么的实现,可惜自己思考力不够,中途放弃,参考成熟的代码通过div的排列,clear:left 清除左边的浮动,实现了浮动元素的换行,另外margin-bottom:-30px;为了使六边形向上的尖角插入,的二行整体左移对应的像素。



css3六边形平铺

标签:css3

原文地址:http://rzhm1205.blog.51cto.com/9425786/1775004

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