【发布时间】:2015-12-14 17:51:59
【问题描述】:
我有以下六边形代码。我需要六边形周围的边框和作为六边形背景的图像,而不是纯色。
body {
background: #ecf0f1;
}
#hex1 {
width: 200px;
height: 200px;
}
#color1 {
background-color: #D93;
}
.hexagon-wrapper {
text-align: center;
margin: 20px;
position: relative;
display: inline-block;
}
.hexagon {
height: 100%;
width: 57.735%;
display: inline-block;
}
.hexagon:before {
position: absolute;
top: 0;
right: 21.1325%;
background-color: inherit;
height: inherit;
width: inherit;
content: '';
transform: rotate(60deg);
}
.hexagon:after {
position: absolute;
top: 0;
right: 21.1325%;
background-color: inherit;
height: inherit;
width: inherit;
content: '';
transform: rotate(-60deg);
}
<div id="hex1" class="hexagon-wrapper">
<span id="color1" class="hexagon"></span>
</div>
这是code的链接
【问题讨论】:
-
您可能会发现这很有帮助 - stackoverflow.com/questions/19418486/…。它与您使用的方法不同,而是采用不同的方法来实现相同的结果。
-
你可能会发现这也很有帮助css-shapes.xyz/hexagon
标签: html css css-shapes