【问题标题】:How to draw polygon background with CSS?如何用 CSS 绘制多边形背景?
【发布时间】:2019-02-26 21:12:59
【问题描述】:

我的页面内容丰富。

我想将一个多边形设置为整个页面的背景,颜色为#E0E6E5。

polygon(0 0, 100% 35%, 100% 65%, 0% 100%)

我该怎么做?

我知道这听起来很简单。 但是我无法使用基本上切断页面的另一半并且不可见的剪辑路径来做到这一点。 静态图像不是一种选择。

我还有其他选择吗?

【问题讨论】:

标签: html css


【解决方案1】:

你想要的形状是这样的:

.box {
 -webkit-clip-path:polygon(0 0, 100% 35%, 100% 65%, 0% 100%);
 clip-path:polygon(0 0, 100% 35%, 100% 65%, 0% 100%);
 width:200px;
 height:200px;
 background:#E0E6E5;
}
<div class="box"></div>

您可以轻松地使用渐变和多个背景:

.box {
 width:200px;
 height:200px;
 background:
   linear-gradient(to bottom left,transparent 49.8%,#E0E6E5 50%) top   /100% 35%,
   linear-gradient(to top    left,transparent 49.8%,#E0E6E5 50%) bottom/100% 35%,
   linear-gradient(#E0E6E5,#E0E6E5) center/100% 30%;
 background-repeat:no-repeat;
}
<div class="box"></div>

【讨论】:

  • 我用 clip-path 做了同样的事情,但它切断了整个页面的白色部分。带有渐变的第二个样本完美地工作!非常感谢。
猜你喜欢
  • 1970-01-01
  • 2021-11-01
  • 1970-01-01
  • 2017-07-19
  • 2011-01-16
  • 2017-10-13
  • 1970-01-01
  • 1970-01-01
  • 2014-03-03
相关资源
最近更新 更多