【问题标题】:Multiple backgrounds without using images不使用图像的多个背景
【发布时间】:2014-06-30 21:18:53
【问题描述】:

是否可以在不使用图像的情况下在 CSS 中使用多个背景?

在我的情况下,我想要前 20 个左右像素的渐变,然后是白色。

【问题讨论】:

    标签: css


    【解决方案1】:

    对于实际的渐变,您可以使用

    background: #113;
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#113), color-stop(20px,#fff));
    background: -webkit-linear-gradient(top, #113 0%,#fff 20px);
    background: linear-gradient(to bottom, #113 0%,#fff 20px);
    background: -moz-linear-gradient(top, #113 0%, #fff 20px);
    background: -ms-linear-gradient(top, #113 0%,#fff 20px);
    background: -o-linear-gradient(top, #113 0%,#fff 20px);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#113', endColorstr='#fff',GradientType=0 );
    

    你也可以使用插入框阴影

    background: #fff;
    box-shadow: inset 0 20px 20px -10px #113;
    

    这也会从顶部创建一个 20px 的暗渐变,变成白色。

    遗憾的是,我还不能上传图片,所以我只想告诉你,渐变和盒子阴影确实略有不同。

    【讨论】:

      【解决方案2】:

      请参阅 ColorZilla 了解梯度生成器 - 这是百分比,但我认为这个想法是正确的

      background: #1e5799; /* Old browsers */
      background: -moz-linear-gradient(top,  #1e5799 0%, #ffffff 25%); /* FF3.6+ */
      background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(25%,#ffffff)); /* Chrome,Safari4+ */
      background: -webkit-linear-gradient(top,  #1e5799 0%,#ffffff 25%); /* Chrome10+,Safari5.1+ */
      background: -o-linear-gradient(top,  #1e5799 0%,#ffffff 25%); /* Opera 11.10+ */
      background: -ms-linear-gradient(top,  #1e5799 0%,#ffffff 25%); /* IE10+ */
      background: linear-gradient(to bottom,  #1e5799 0%,#ffffff 25%); /* W3C */
      filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#ffffff',GradientType=0 ); /* IE6-9 */
      

      【讨论】:

      • 谢谢,其实我知道ColorZilla,但你以为你只能指定百分比的位置?如果您手动操作,您可以使用像素而不是 % 吗?
      • @Juicy:它在 Chrome 中对我有用,但这个答案可能会给你在一般情况下你想要的东西:stackoverflow.com/a/8861026/446747
      猜你喜欢
      • 1970-01-01
      • 2018-11-03
      • 2011-08-16
      • 2011-07-22
      • 2011-05-26
      • 2013-05-13
      • 2019-08-18
      • 2022-11-10
      • 1970-01-01
      相关资源
      最近更新 更多