【问题标题】:Box with clipped corners带剪角的盒子
【发布时间】:2017-05-17 05:44:38
【问题描述】:

我需要一个带有所有剪角的盒子。到目前为止,这是我所拥有的:

body {
  height: 200px;
  background: -webkit-linear-gradient(left, rgba(255, 0, 0, 0), rgba(255, 0, 0, 1));
  background: -o-linear-gradient(right, rgba(255, 0, 0, 0), rgba(255, 0, 0, 1));
  background: -moz-linear-gradient(right, rgba(255, 0, 0, 0), rgba(255, 0, 0, 1));
  background: linear-gradient(to right, rgba(255, 0, 0, 0), rgba(255, 0, 0, 1));
}

#block {
  width: 330px;
  height: 200px;
  margin-left: 20%;
  background-color: #222;
  -webkit-clip-path: polygon(4% 0, 96% 0, 100% 9%, 100% 90%, 96% 100%, 4% 100%, 0 90%, 0 10%);
  clip-path: polygon(4% 0, 96% 0, 100% 9%, 100% 90%, 96% 100%, 4% 100%, 0 90%, 0 10%)
}
<div id="block"></div>

很遗憾,没有 Edge 支持,我不能使用 box-shadow。有没有其他方法可以做到这一点?

【问题讨论】:

  • 使用border-radius怎么样?没有那么多控制,但会剪辑。

标签: html css css-shapes


【解决方案1】:

我们可以使用溢出隐藏和旋转的伪元素来做点什么吗?

.box{
  width:100px;
  height:100px;
  position:relative;
  overflow:hidden;
 }
.box:after{
  content: '';
  width:120px;
  height:120px;
  position:absolute;
  background:#465;
  left:50%;
  top:50%;
  transform:translateX(-50%) translateY(-50%) rotateZ(45deg);
}
<div class="box"></div>

【讨论】:

  • 谢谢。效果很好。 ^^
猜你喜欢
  • 1970-01-01
  • 2012-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-02-02
  • 2011-12-23
相关资源
最近更新 更多