html - CSS以像素为单位设置多种颜色渐变?

标签 html css linear-gradients

如何在 y 轴坐标 1、2、3、4、5 和 6 上从上到下绘制出 6 种不同的颜色,这些颜色各占 1 px,第 7 种颜色占其余的股利?我试过这个但它不起作用:

background-image: linear-gradient(to bottom, #e2e2e2 0%, #e8e8e8 2px, #efefef 3px, #f4f4f4 4px, #f7f7f7 5px, #f8f8f8 6px, #f9f9f9 100%);

最佳答案

尝试如下:

html {
 min-height:100%;
 background-image: 
  linear-gradient(to bottom, 
    orange  0 10px, 
    red     0 20px, 
    purple  0 30px, 
    green   0 40px, 
    #f7f7f7 0 50px, 
    blue    0 60px, 
    yellow 0);
}

如果你想要一个淡入淡出的过渡,或者像这样

html {
 min-height:100%;
 background-image: 
  linear-gradient(to bottom, 
    orange  10px, 
    red     20px, 
    purple  30px, 
    green   40px, 
    #f7f7f7 50px, 
    blue    60px, 
    yellow  0);
}

另一个多重渐变的想法:

html {
 min-height:100%;
 background: 
  linear-gradient(to bottom, 
    orange  , 
    red     , 
    purple  , 
    green   , 
    #f7f7f7 , 
    blue    ) top/100% 25% no-repeat, /* 25% = height */
   yellow;
}

关于html - CSS以像素为单位设置多种颜色渐变?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59529214/

相关文章:

css - 具有图像和线性渐变的多个背景的无效属性值

php - 产品缩略图中的云缩放效果

html - 移动导航栏的问题

html - 如何更改 Chrome 中 <select> 元素中所选选项的字体大小?

javascript - 打开时灯箱未对齐

android - 从指定位置偏移绘制线性渐变

javascript - 未选择文件时禁用提交按钮

css - 复制图像并设置悬停 CSS

javascript - Thymeleaf 找到 CSS 和 JS 文件,但不解释它们。为什么?

html - 如何在不使用背景位置的情况下为线性渐变设置动画?