簡體   English   中英

中心CSS3六角形

[英]Center CSS3 Hexagon

我喜歡在div內居中放置CSS3六角形(請看下面的屏幕截圖)。 我使用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/

在此處輸入圖片說明

您可以將auto添加到margin 工作演示

.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;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM