How can I make the gradient stops in a CSS3 linear gradient?

泪湿孤枕 提交于 2019-12-05 22:51:23

Have a white gradient fading in opacity up to 50% over your desired background color. This method can be used on any background color without changing the gradient CSS.

Demo: 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>

Output:

It should work.

#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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!