css - 创建带 Angular 线性渐变

标签 css linear-gradients

我的设计规范要求这样的渐变

enter image description here

我弄清楚了如何进行斜线和颜色偏移,但在相同的线性渐变属性中完成这两项工作时遇到困难。

background: linear-gradient(90deg, #007bff, #0C4078); // color is right 
background: linear-gradient(178deg, white 50%, white 50%, #007bff 50%, #007bff 40%); // line angle is right

如何使我的线性渐变看起来像规范?

最佳答案

您需要考虑多种背景:

.box {
 height:200px;
 background: 
   linear-gradient(to bottom right,#fff 49%,transparent 50%) top/100% 30%,
   linear-gradient(to right, #007bff, #0C4078);
 background-repeat:no-repeat;
}
<div class="box"></div>

如果您想要透明度,可以使用带有一个背景的clip-path:

.box {
 height:200px;
 background:linear-gradient(to right, #007bff, #0C4078);
 -webkit-clip-path:polygon(0 30%,0 100%, 100% 100%,100% 0);
 clip-path:polygon(0 30%,0 100%, 100% 100%,100% 0);
}
<div class="box"></div>

掩码

.box {
 height:200px;
 background: linear-gradient(to right, #007bff, #0C4078);
 -webkit-mask:
  linear-gradient(to bottom right,transparent 49%,white 50%) top/100% 30% no-repeat,
  linear-gradient(white,white) bottom/100% 70% no-repeat;
 mask:
  linear-gradient(to bottom right,transparent 49%,white 50%) top/100% 30% no-repeat,
  linear-gradient(white,white) bottom/100% 70% no-repeat;
}
<div class="box"></div>


如果您想要透明度和比 clip-path/mask 更好的支持,这里是另一种方法:

.box {
  height: 200px;
  position: relative;
  overflow: hidden;
  z-index: 0;
}

.box:before {
  content: "";
  position: absolute;
  z-index: -1;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  transform: skewY(-5deg);
  transform-origin: right;
  background: linear-gradient(to right, #007bff, #0C4078);
}
<div class="box"></div>

关于css - 创建带 Angular 线性渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52959491/

相关文章:

html - 如何在使用 &lt;input name ="photo"type ="file"/> 上传文件后立即显示照片?

css - 如何在CSS中创建3种颜色的渐变而不进行颜色升级

带有渐变尾部的笔划的 SVG 圆

css - 线性渐变提前结束

具有 2 行、4 列、7 个元素的 CSS 网格。如何使第二行居中?

javascript - 在溢出 :hidden 的 div 父级内显示弹出窗口

html - 垂直居中两个div

css - 我可以在包含背景图片的 html 表格后面放置一个 html img 标签吗?

android - LinearGradient中心动画

javascript - 如果我有线性渐变,则更改滚动上的颜色背景