如何在<div>元素周围创建凹形边框?

时间:2016-11-22 10:08:07

标签: html css border css-shapes concave

我正试图围绕<div>制作凹形顶部和底部边框,如下所示:

Example of what I would like to do

我目前的CSS:

.div:after {    
    content:'';
    position:absolute;
    left:-600%;
    width:1300%;
    padding-bottom:1300%;
    top:80%;
    background:none;
    border-radius:50%;
    box-shadow: 0px 0px 0px 20px #f2f2f2;
    z-index:-1;
}

但它只适用于底部边框,有时会在移动设备上消失。

这是JS Fiddle

1 个答案:

答案 0 :(得分:2)

您可以使用:before:after伪元素绘制此形状。

&#13;
&#13;
.div {
  position: relative;
  overflow: hidden;
  padding: 50px 0;
}

.div-inner {
  position: relative;
  background: black;
  height: 120px;
}

.div-inner:before,
.div-inner:after {
  box-shadow: 0 0 0 80px #000;
  border-radius: 100%;
  position: absolute;
  height: 150px;  /* You can change height to increase or decrease concave radius */ 
  content: '';
  right: -20%;
  left: -20%;
  top: 100%;
}

.div-inner:after {
  bottom: 100%;
  top: auto;
}
&#13;
<div class="div">
  <div class="div-inner"></div>
</div>
&#13;
&#13;
&#13;