html - 中心 CSS3 六边形

标签 html forms css

我喜欢将 CSS3 六边形置于 div 的中心(请查看下面的屏幕截图)。我使用 Foundation Framework,因此 Hexagon 由列包装器包装(在本例中使用类“warpper”)。

我的 CSS:

.wrapper {
    width: 1000px;
}

.hexagon {
  position: relative;
  width: 300px; 
  height: 173.21px;
  margin: 86.60px 0;
  background-image: url(http://csshexagon.com/img/meow.jpg);
  background-size: auto 346.4102px;
  background-position: center;
}

.hexTop,
.hexBottom {
  position: absolute;
  z-index: 1;
  width: 212.13px;
  height: 212.13px;
  overflow: hidden;
  -webkit-transform: scaleY(0.5774) rotate(-45deg);
  -ms-transform: scaleY(0.5774) rotate(-45deg);
  transform: scaleY(0.5774) rotate(-45deg);
  background: inherit;
  left: 43.93px;
}

/*counter transform the bg image on the caps*/
.hexTop:after,
.hexBottom:after {
  content: "";
  position: absolute;
  width: 300.0000px;
  height: 173.20508075688775px;
  -webkit-transform:  rotate(45deg) scaleY(1.7321) translateY(-86.6025px);
  -ms-transform:      rotate(45deg) scaleY(1.7321) translateY(-86.6025px);
  transform:          rotate(45deg) scaleY(1.7321) translateY(-86.6025px);
  -webkit-transform-origin: 0 0;
  -ms-transform-origin: 0 0;
  transform-origin: 0 0;
  background: inherit;
}

.hexTop {
  top: -106.0660px;
}

.hexTop:after {
  background-position: center top;
}

.hexBottom {
  bottom: -106.0660px;
}

.hexBottom:after {
  background-position: center bottom;
}

.hexagon:after {
  content: "";
  position: absolute;
  top: 0.0000px;
  left: 0;
  width: 300.0000px;
  height: 173.2051px;
  z-index: 2;
  background: inherit;
}

我在 JSFiddle 上的完整代码:http://jsfiddle.net/oa0j4ba8/1/

enter image description here

最佳答案

您可以将auto 添加到margin working demo

.hexagon {
  position: relative;
  width: 300px;
  height: 173.21px;
  margin: 86.60px auto;/*replace 0 with auto here*/
  background-image: url(http://csshexagon.com/img/meow.jpg);
  background-size: auto 346.4102px;
  background-position: center;
}

关于html - 中心 CSS3 六边形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28890036/

相关文章:

html - 手机下拉菜单

javascript - 创建 HTML 选项卡

html - accept-charset ="UTF-8"参数在表单中使用时不执行任何操作

android - 编辑文本行间距额外问题

使用 iTextSharp XMLWorker 将 HTML 转换为 PDF 时,CSS 不适用

html - 如何在使用图像类型按钮以 HTML 表单提交时删除 x 和 y?

php - 无法在 PHP 中访问表单数据

arrays - 如何使用 Django 在 HTML post 请求中发送数组

javascript - 如何将标签直接放在跨度下?

html - CSS 图像和伪元素过渡不同步