【问题标题】:Responsive Hexagon grid with a border带边框的响应式六边形网格
【发布时间】:2015-10-03 19:00:40
【问题描述】:
http://codepen.io/web-tiki/pen/HhCyd

我正在使用来自类似问题的上述笔。我能够编辑六边形的大小,编辑宽度属性和填充,但我想为六边形添加一个边框,我可以通过添加一个边框和编辑框的大小来在六边形的左侧和右侧category li div 元素,但无法通过编辑 category li 元素获取六边形的另一边。

body{
  font-family: 'Open Sans', arial, sans-serif;
  background:rgb(0, 0, 0);

}
*{
  margin:0;
  padding:0;
}
#categories{
  overflow:hidden;
  width:90%;
  margin:0 auto;
}
.clr:after{
  content:"";
  display:block;
  clear:both;
}
#categories li{
  position:relative;
  border-style: solid;
  border-width:10px; 
  list-style-type:none;
  width:27.85714285714286%; /* = (100-2.5) / 3.5 */
  padding-bottom: 32.16760145166612%; /* =  width /0.866 */
  float:left;
  overflow:hidden;
  visibility:hidden;

  -webkit-transform: rotate(-60deg) skewY(30deg);
  -ms-transform: rotate(-60deg) skewY(30deg);
  transform: rotate(-60deg) skewY(30deg);
}
#categories li:nth-child(3n+2){
  margin:0 1%;
}
#categories li:nth-child(6n+4){
  margin-left:0.5%;
}
#categories li:nth-child(6n+4), #categories li:nth-child(6n+5), #categories li:nth-child(6n+6) {
  margin-top: -6.9285714285%;
  margin-bottom: -6.9285714285%;

  -webkit-transform: translateX(50%) rotate(-60deg) skewY(30deg);
  -ms-transform: translateX(50%) rotate(-60deg) skewY(30deg);
  transform: translateX(50%) rotate(-60deg) skewY(30deg);
}
#categories li:nth-child(6n+4):last-child, #categories li:nth-child(6n+5):last-child, #categories li:nth-child(6n+6):last-child{
  margin-bottom:0%;
}
#categories li *{
  position:absolute;
  visibility:visible;
}
#categories li > div{
  border-style: solid;
  border-width: 5px;
  box-sizing:border-box;
  width:100%;
  height:100%;
  text-align:center;
  color:#fff;
  overflow:hidden;

  -webkit-transform: skewY(-30deg) rotate(60deg);
  -ms-transform: skewY(-30deg) rotate(60deg);
  transform: skewY(-30deg) rotate(60deg);

  -webkit-backface-visibility:hidden;

}

/* HEX CONTENT */
#categories li img{
  left:-100%; right:-100%;
  width: auto; height:100%;
  margin:0 auto;   
}

#categories div h1, #categories div p{
  width:90%;
  padding:0 5%;
  background-color:#008080; background-color: rgba(0, 128, 128, 0.8);
  font-family: 'Raleway', sans-serif;

  -webkit-transition: top .2s ease-out, bottom .2s ease-out, .2s padding .2s ease-out;
  -ms-transition: top .2s ease-out, bottom .2s ease-out, .2s padding .2s ease-out;
  transition: top .2s ease-out, bottom .2s ease-out, .2s padding .2s ease-out;
}
#categories li h1{
  bottom:110%;
  font-style:italic;
  font-weight:normal;
  font-size:1.5em;
  padding-top:100%;
  padding-bottom:100%;
}
#categories li h1:after{
  content:'';
  display:block;
  position:absolute;
  bottom:-1px; left:45%;
  width:10%;
  text-align:center;
  z-index:1;
  border-bottom:2px solid #fff;
}
#categories li p{
  padding-top:50%;
  top:110%;
  padding-bottom:50%;
}


/* HOVER EFFECT  */

#categories li div:hover h1 {
  bottom:50%;
  padding-bottom:10%;
}

#categories li div:hover p{
  top:50%;
  padding-top:10%;
}

【问题讨论】:

    标签: html css hexagonal-tiles


    【解决方案1】:

    这对我来说效果很好,希望对你也有帮助。

    <div class="hexagon"></div>
    
    .hexagon {
      position: relative;
      width: 300px; 
      height: 173.21px;
      background-color: #64C7CC;
      margin: 86.60px 0;
      border-left: solid 5px #333333;
      border-right: solid 5px #333333;
    }
    
    .hexagon:before,
    .hexagon:after {
      content: "";
      position: absolute;
      z-index: 1;
      width: 212.13px;
      height: 212.13px;
      -webkit-transform: scaleY(0.5774) rotate(-45deg);
      -ms-transform: scaleY(0.5774) rotate(-45deg);
      transform: scaleY(0.5774) rotate(-45deg);
      background-color: inherit;
      left: 38.9340px;
    }
    
    .hexagon:before {
      top: -106.0660px;
      border-top: solid 7.0711px #333333;
      border-right: solid 7.0711px #333333;
    }
    
    .hexagon:after {
      bottom: -106.0660px;
      border-bottom: solid 7.0711px #333333;
      border-left: solid 7.0711px #333333;
    }
    

    对于六边形内的图像,请使用:

    <div class="hexagon">
      <div class="hexTop"></div>
      <div class="hexBottom"></div>
    </div>
    
    .hexagon {
      position: relative;
      width: 300px; 
      height: 173.21px;
      margin: 86.60px 0;
      background-image: url(http://you_image_url.jpg);
      background-size: auto 334.8632px;
      background-position: center;
      border-left: solid 5px #333333;
      border-right: solid 5px #333333;
    }
    
    .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: 38.93px;
    }
    
    /*counter transform the bg image on the caps*/
    .hexTop:after,
    .hexBottom:after {
      content: "";
      position: absolute;
      width: 290.0000px;
      height: 167.4315780649915px;
      -webkit-transform:  rotate(45deg) scaleY(1.7321) translateY(-83.7158px);
      -ms-transform:      rotate(45deg) scaleY(1.7321) translateY(-83.7158px);
      transform:          rotate(45deg) scaleY(1.7321) translateY(-83.7158px);
      -webkit-transform-origin: 0 0;
      -ms-transform-origin: 0 0;
      transform-origin: 0 0;
      background: inherit;
    }
    
    .hexTop {
      top: -106.0660px;
      border-top: solid 7.0711px #333333;
      border-right: solid 7.0711px #333333;
    }
    
    .hexTop:after {
      background-position: center top;
    }
    
    .hexBottom {
      bottom: -106.0660px;
      border-bottom: solid 7.0711px #333333;
      border-left: solid 7.0711px #333333;
    }
    
    .hexBottom:after {
      background-position: center bottom;
    }
    
    .hexagon:after {
      content: "";
      position: absolute;
      top: 2.8868px;
      left: 0;
      width: 290.0000px;
      height: 167.4316px;
      z-index: 2;
      background: inherit;
    }
    

    【讨论】:

      猜你喜欢
      • 2014-11-24
      • 2013-05-20
      • 2016-09-09
      • 1970-01-01
      • 1970-01-01
      • 2013-10-25
      • 2016-07-28
      相关资源
      最近更新 更多