【发布时间】:2015-01-12 23:01:21
【问题描述】:
我正在尝试创建一个内部带有图像的六边形
我不想把背景放在css里面,我想用html来做
我该怎么做?
HTML
<div class="hexagon"><img src="http://www.edinphoto.org.uk/0_STREET/0_street_views_-_arden_street_2006_barry_nelson.jpg" width="200" height="200" /></div>
CSS
.hexagon {
position: relative;
width: 150px;
height: 86.60px;
background-color: #64C7CC;
margin: 43.30px 0;
float:left;
margin-right:10px;
}
.hexagon:before,
.hexagon:after {
content: "";
position: absolute;
width: 0;
border-left: 75px solid transparent;
border-right: 75px solid transparent;
}
.hexagon:before {
bottom: 100%;
border-bottom: 43.30px solid #64C7CC;
}
.hexagon:after {
top: 100%;
width: 0;
border-top: 43.30px solid #64C7CC;
}
【问题讨论】:
-
你会使用纯色背景吗?此外,您提供的小提琴也不是很令人满意:如果您查看开发工具,您会注意到
.hexagon的大小(在 CSS 中指定)比图像小得多。 -
对于使用 img 标签的响应式六边形网格,您可以查看stackoverflow.com/questions/26114920/…