.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;为了使六边形向上的尖角插入,的二行整体左移对应的像素。
时间: 2024-10-09 18:07:45