Hexagonal Images [duplicate]

2019-07-14 00:29发布

This question already has an answer here:

Circle Images

I can get circle borders using border-radius:

img {
  border-radius: 50%;
}

Hexagonal Images

I'm hoping to create hexagonal images though. I'm guessing that wrapping the images in a div/span (or a few of them) will be required.

Something like either of these:

For simplicity's sake, all images are square.

Objective

The point of getting images like this is to stack them in a honeycomb like structure. I'm not putting this as part of the question as it should be relatively easy to achieve if I can get my images hexagonal.

1条回答
走好不送
2楼-- · 2019-07-14 01:20

How about clip-path...

img {
  -webkit-clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
clip-path: polygon(50% 0%, 100% 25%, 100% 75%, 50% 100%, 0% 75%, 0% 25%);
}
<img src="http://placehold.it/200">

Here is a jazzy tool for easily generating the clip-path attribute. And here is a nice article with more information.

查看更多
登录 后发表回答