复杂形状的边界半径

时间:2016-10-26 09:50:39

标签: css css3

我试图将以下形状作为css。有人帮助我得到任何类型的教程或代码片段如何将这个形状之王作为css?

enter image description here

2 个答案:

答案 0 :(得分:2)

你需要一些额外的元素,两个在左边和右边创建东西。

注意:这仅适用于纯色背景(在这种情况下,.ws_left:before上使用的白色背景和.ws_right:before

body { margin: 5em; }
.ws {
  position: relative;
  width: 15em;
  height: 15em;
  background: gray;
  border-radius: 0 0 1em 1em;
}
.ws_left {
  position: absolute;
  top: 0;
  left: -4em;
  right: 100%;
  height: 2.5em;
  background: gray;
  border-radius: 1em 0 0 1em;
}
  .ws_left:before, .ws_left:after,
  .ws_right:before, .ws_right:after {
    content: '';
    position: absolute;
    background: red;
    width: 1em;
    height: 1em;
    top: 100%;
    right: 0;
    z-index: 1;
  }
  .ws_left:before {
    border-top-right-radius: 1em;
    background: white;
    z-index: 2;
  }
  .ws_left:after {
    background: gray;
  }

  .ws_right:before, .ws_right:after {
    right: auto;
    left: 0;
  }
  .ws_right:before {
    border-top-left-radius: 1em;
    background: white;
    z-index: 2;
  }
  .ws_right:after {
    background: gray;
  }
.ws_right {
  position: absolute;
  top: 0;
  left: 100%;
  right: -2em;
  height: 2.5em;
  background: gray;
  border-radius: 0 1em 1em 0;
}
<div class="ws">
  <div class="ws_left"></div>
  <div class="ws_right"></div>
</div>

答案 1 :(得分:2)

我希望对你有所帮助: -

.maindiv{ background:#4C4B4B; width:400px; height:330px; border-radius:12px; position:relative; margin:auto;}
.maindiv::after {
  background: #4c4b4b none repeat scroll 0 0;
  border-radius: 25px 0 0 25px;
  content: "";
  display: inline-block;
  height: 50px;
  left: -90px;
  position: absolute;
  width: 100px;
}
.maindiv::before {
  background: #4c4b4b none repeat scroll 0 0;
  border-radius: 0 25px 25px 0;
  content: "";
  display: inline-block;
  height: 50px;
  right: -90px;
  position: absolute;
  width: 100px;
}
#simulated {
  left: -30px;
  position: absolute;
  top: 29px;
  transform: rotate(-90deg);
  z-index: 9999;
}
#simulated2 {
  right: -30px;
  position: absolute;
  top: 29px;
  transform: rotate(161deg);
  z-index: 9999;
}
#simulated path, #simulated2 path {
  fill:#4c4b4b;
}
<div class="maindiv">
<svg width="60" height="60" id="simulated">
	<path d="M 40 0 h 320 a 40 30 0 0 0 40 30 v 240 a 40 30 0 0 0 -40 30 h -320 a 40 30 0 0 0 -40 -30 v -240 a 40 30 0 0 0 40 -30 Z"/>
</svg>
<svg width="60" height="60" id="simulated2">
	<path d="M 40 0 h 320 a 40 30 0 0 0 40 30 v 240 a 40 30 0 0 0 -40 30 h -320 a 40 30 0 0 0 -40 -30 v -240 a 40 30 0 0 0 40 -30 Z"/>
</svg>
</div>