【问题标题】:How can I make the gradient stops in a CSS3 linear gradient?如何使渐变停止在 CSS3 线性渐变中?
【发布时间】:2012-01-09 18:39:38
【问题描述】:

请参阅此示例页面中的灰色条:

http://dss.com.bo/inicio.aspx

这是我使用 CSS3 重新创建渐变的尝试 - 也使用 CSS3PIE

#navigation {
    border: 1px solid #888888;
    border-radius: 22px;
    -moz-border-radius: 22px;
    -webkit-border-radius: 22px;    
    height: 50px;
    font-family: Arial;    
    background: #AAAAAA;
    background: -webkit-gradient(linear, 0 0, 0 bottom, from(#AAAAAA), to(#757575));
    background: -webkit-linear-gradient(#AAAAAA, #757575);
    background: -moz-linear-gradient(#AAAAAA, #757575);
    background: -ms-linear-gradient(#AAAAAA, #757575);
    background: -o-linear-gradient(#AAAAAA, #757575);
    background: linear-gradient(#AAAAAA, #757575);
    -pie-background: linear-gradient(#AAAAAA, #757575);
    behavior: url(/Public/stylesheets/PIE.htc);
}

这导致:

如何减少渗色效果,使颜色过渡更难?

【问题讨论】:

  • 为什么不把它作为答案?
  • @roXon:该 jsbin 链接有效,但破坏了 PIE 功能并且渐变边框半径不再出现。知道为什么它不起作用吗?

标签: css linear-gradients


【解决方案1】:

让白色渐变的不透明度比您想要的背景颜色最多降低 50%。此方法可用于任何背景颜色,而无需更改渐变 CSS。

演示:http://jsfiddle.net/ThinkingStiff/Zn5Qb/

CSS:

#header { 
    background-color: #595454;
    background-image: linear-gradient( 
            top, 
            rgba( 255, 255, 255, .4 ) 0%, 
            rgba( 255, 255, 255, .1 ) 50%,
            rgba( 255, 255, 255, .0 ) 50.5%, 
            rgba( 255, 255, 255, .0 ) 100% );
        background-image: -webkit-linear-gradient( 
            top, 
            rgba( 255, 255, 255, .4 ) 0%, 
            rgba( 255, 255, 255, .1 ) 50%,
            rgba( 255, 255, 255, .0 ) 50.5%, 
            rgba( 255, 255, 255, .0 ) 100% );
        background-image: -moz-linear-gradient( 
            top, 
            rgba( 255, 255, 255, .4 ) 0%, 
            rgba( 255, 255, 255, .1 ) 50%,
            rgba( 255, 255, 255, .0 ) 50.5%, 
            rgba( 255, 255, 255, .0 ) 100% );
        background-image: -o-linear-gradient( 
            top, 
            rgba( 255, 255, 255, .4 ) 0%, 
            rgba( 255, 255, 255, .1 ) 50%,
            rgba( 255, 255, 255, .0 ) 50.5%, 
            rgba( 255, 255, 255, .0 ) 100% );
        background-image: -ms-linear-gradient( 
            top, 
            rgba( 255, 255, 255, .4 ) 0%, 
            rgba( 255, 255, 255, .1 ) 50%,
            rgba( 255, 255, 255, .0 ) 50.5%, 
            rgba( 255, 255, 255, .0 ) 100% );
    height: 42px;
    width: 100%;
}

HTML:

<div id="header"></div>

输出:

【讨论】:

    【解决方案2】:

    它应该可以工作。

    #menu-bg {
      border: 1px solid #888888;
      border-radius: 22px;
      -moz-border-radius: 22px;
      -webkit-border-radius: 22px;    
      height: 50px;
      font-family: Arial; 
      background: #868686; /* Old browsers */
      background: -moz-linear-gradient(top,  #868686 0%, #727272 49%, #5e5e5e 51%, #747474 100%); /* FF3.6+ */
      background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#868686), color-stop(49%,#727272), color-stop(51%,#5e5e5e), color-stop(100%,#747474)); /* Chrome,Safari4+ */
      background: -webkit-linear-gradient(top,  #868686 0%,#727272 49%,#5e5e5e 51%,#747474 100%); /* Chrome10+,Safari5.1+ */
      background: -o-linear-gradient(top,  #868686 0%,#727272 49%,#5e5e5e 51%,#747474 100%); /* Opera 11.10+ */
      background: -ms-linear-gradient(top,  #868686 0%,#727272 49%,#5e5e5e 51%,#747474 100%); /* IE10+ */
      background: linear-gradient(top,  #868686 0%,#727272 49%,#5e5e5e 51%,#747474 100%); /* W3C */
      filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#868686', endColorstr='#747474',GradientType=0 ); /* IE6-9 */
    }
    
        <div id="menu-bg"></div>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-02-28
      • 1970-01-01
      • 2021-06-30
      • 1970-01-01
      • 1970-01-01
      • 2014-12-26
      • 2011-11-24
      相关资源
      最近更新 更多