【发布时间】:2015-03-17 19:32:49
【问题描述】:
我正在尝试创建一个图像为八角形的设计。我使用了边框技巧,但图像需要在八角形内。在这种情况下不适合使用伪元素,因为主体也会有自己的背景图像。用css可以吗?
我的代码
div {
width: 100vh;
height: 100vh;
background: gold;
position: relative;
}
div:before {
content: "";
position: absolute;
top: 0;
left: 0;
border-bottom: 29vh solid gold;
border-left: 29vh solid white;
border-right: 29vh solid white;
width: 42vh;
height: 0;
}
div:after {
content: "";
position: absolute;
bottom: 0;
left: 0;
border-top: 29vh solid gold;
border-left: 29vh solid white;
border-right: 29vh solid white;
width: 42vh;
height: 0;
}
<div></div>
我希望这张图片位于黄金区域:http://images.visitcanberra.com.au/images/canberra_hero_image.jpg。另外,我使用 vh 以便它响应窗口高度。
【问题讨论】:
标签: html css geometry css-shapes