使用css和js动态创建六边形设计

any*_*ime 6 html javascript css css3 css-shapes

这不是重复的任何请帮助我

我在这里得到了一些技巧http://jsfiddle.net/kizu/bhGn4/

我想用它动态创建它CSS,那么怎么做呢?

每当添加到设计中的任何新条目自动调整时.

我努力搜索,我在这里获得了圆形的帮助

如何用css,javascript创建一个圆圈?

我想要六角形的东西

在此输入图像描述

Har*_*ari 2

看看我创建的这个演示:

.hexagon {
  width: 100px;
  height: 55px;
  background: red;
  position: absolute;
}
.hexagon:before {
  content: "";
  position: absolute;
  top: -25px;
  left: 0;
  width: 0;
  height: 0;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  border-bottom: 25px solid red;
}
.hexagon:after {
  content: "";
  position: absolute;
  bottom: -25px;
  left: 0;
  width: 0;
  height: 0;
  border-left: 50px solid transparent;
  border-right: 50px solid transparent;
  border-top: 25px solid red;
}
.hex1 {
  top: 20px;
  left: 0px;
}
.hex2 {
  top: 20px;
  left: 110px;
}
.hex3 {
  top: 20px;
  left: 220px;
}
.hex4 {
  top: 110px;
  left: 55px;
}
.hex5 {
  top: 110px;
  left: 165px;
}
.hex6 {
  top: 110px;
  left: 275px;
}
Run Code Online (Sandbox Code Playgroud)
<div style="position:absolute; top:30px">
  <div class="hexagon hex1"></div>
  <div class="hexagon hex2"></div>
  <div class="hexagon hex3"></div>
  <div class="hexagon hex4"></div>
  <div class="hexagon hex5"></div>
  <div class="hexagon hex6"></div>
</div>
Run Code Online (Sandbox Code Playgroud)