Responsive grid of hexagons

后端 未结 9 560
礼貌的吻别
礼貌的吻别 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:06

    instead of using class in img tag use css in container img like

    .container img{ your code}
    

    it will save you a lot trouble of putting class in images

    0 讨论(0)
  • 2020-11-22 10:08

    if it is about honeycombing, bee nest css here is a CSS possibilitie. http://codepen.io/gc-nomade/pen/eyntg/

      <div><!-- even div gets a negative bottom margin. all of them gets a negative right margin -->
      <span><!-- skewed and rotated -->
        <img src="http://lorempixel.com/200/200/food/1"/><!-- rotated back, unskewed and rescaled -->
      </span>
    </div>
    
    0 讨论(0)
  • 2020-11-22 10:09

    Alright, here's a clean, cross-browser compatible solution that will even allow you to honeycomb the hexagons:

    For this to work, you need to wrap each image in 2 containers, since one will be used for the top left / bottom right cut-off and the other for the top right / bottom left cut-off.

    <div class="outerclip">
        <div class="innerclip">
            <img src="http://img1.wikia.nocookie.net/__cb20090714124528/firefly/images/thumb/1/11/Firefly_class_ship.jpg/100px-136,568,0,431-Firefly_class_ship.jpg" />
        </div>
    </div>
    

    The CSS then gives each cut-off container a skew that adds the angles to the image:

    .outerclip {
        -webkit-transform: skew(-30deg);
        -ms-transform: skew(-30deg);
        -transform: skew(-30deg);
        overflow: hidden;
        display: inline-block;
    }
    .innerclip {
        -webkit-transform: skew(50deg);
        -ms-transform: skew(50deg);
        transform: skew(50deg);
        overflow: hidden;
        display: inline-block;
    }
    img {
        -webkit-transform: skew(-30deg);
        -ms-transform: skew(-30deg);
        transform: skew(-30deg);
    }
    

    Demo: http://jsfiddle.net/XkQtF/3/

    Note: to improve the render quality, I'd advise to give both .outerclip and .innerclip the same fixed height.

    To get the honeycombs, you can put several images in a row container and then offset each odd row by a couple of pixels like this:

    Honeycombs

    Demo: http://jsfiddle.net/XkQtF/4/

    0 讨论(0)
提交回复
热议问题