【发布时间】:2018-07-08 03:07:07
【问题描述】:
这是我想要实现的布局:
我用这个 css 创建了六边形:
.hexagon {
width: 100px;
height: 55px;
background: red;
position: relative;
display:inline-block;
margin:0.2em;
}
.hexagon:before {
content: "";
position: absolute;
top: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 25px solid red;
}
.hexagon:after {
content: "";
position: absolute;
bottom: -25px;
left: 0;
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 25px solid red;
}
但是,我正在寻找如何用图像填充它们。 这是一支笔:https://codepen.io/1istbesser/pen/ddypXK
如何将图像放在六边形内以使其覆盖所有内容?如果我在#hexagon1 上使用背景图像,图像只覆盖中间部分。
【问题讨论】:
-
请分享您的背景图片网址。在 codepen 中它没有显示
-
您可以使用例如 via.placeholder.com/350x150 来处理此类问题
-
@JeremyThille 为什么你认为它是重复的?我没有看到任何关系