我需要为这个“形状”添加边框。由于该形状是使用伪元素after和before创建的,因此有点困难。我找不到正确的方法。
我需要实现的目标是: 我目前的代码:
我需要实现的目标是: 我目前的代码:
https://jsfiddle.net/jimmyadaro/xfcjfz3d/
#octagon {
width: 300px;
height: 200px;
background: red;
position: relative;
-webkit-box-sizing: content-box;
-moz-box-sizing: content-box;
box-sizing: content-box;
display: block;
}
#octagon:before,
#octagon:after {
content: "";
position: absolute;
left: 0;
right: 0;
}
#octagon:before {
top: 0;
border-bottom: 30px solid red;
border-left: 30px solid #fff;
border-right: 30px solid #fff;
}
#octagon:after {
bottom: 0;
border-top: 30px solid red;
border-left: 30px solid #fff;
border-right: 30px solid #fff;
}
<div id="octagon"></div>
我尝试使用阴影和轮廓线,但没有成功。
感谢您的阅读。
注意: 如果这很重要,我将使用纯色背景。