Responsive grid of hexagons

后端 未结 9 577
礼貌的吻别
礼貌的吻别 2020-11-22 09:30

I loaded in multiple images on my website from the internet. Is it possible to give all those images an hexagon shape in a responsive grid?

         


        
9条回答
  •  一生所求
    2020-11-22 10:00

    Demo

    HTML:

    SASS (with Compass):

    $width: 400px;
    $fillColor: #CCC;
    $height: $width*sin(60deg);
    .hexagon {
      display: inline-block;
      position: relative;
      width: $width;
    }
    .hexagon:before, .hexagon:after {
      content: '';
      display: block;
      width: 50%;
      border: 0 solid transparent;
    }
    .hexagon:before {
      border-bottom-color: $fillColor;
      border-width: 0 $width/4 $height/2;
    }
    .hexagon:after {
      border-top-color: $fillColor;
      border-width: $height/2 $width/4 0;
    }
    .hexagon > .contents {
      position: absolute;
      top: 0; bottom: 0;
      left: 25%; right: 25%; 
    }
    

    Then, if you want to place an image in the hexagon, inside .contents use

    
    

    and, for example, style it like this:

    #myimg {
      position: absolute;
      top: 0; bottom: 0;
      left: 0; right: 0; 
      margin: auto;
      width: 50%;
    }
    

提交回复
热议问题