【问题标题】:How to fade a box shadow in CSS?如何在 CSS 中淡化盒子阴影?
【发布时间】:2012-09-25 14:56:48
【问题描述】:

注意我已经看过this post 并且无法模仿它。我正在尝试在British Council Sweden 站点上复制阴影:

据我所知,my own site:

我还不能发布图片,但 HTML 的结构如下:

<div id="inner">
<!--Full width div, blue bar of color here-->

    <div class="wrap">
    <!--Existing gradient background image here-->

         <div id="content-wrapper">
         <!--Content begins-->
         </div>

     </div>

</div> 

现有的 CSS:

#inner{
    background: #1e5799;
    background: -moz-linear-gradient(top,  #1e5799 0%, #0057be 100%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#1e5799), color-stop(100%,#0057be));
    background: -webkit-linear-gradient(top,  #1e5799 0%,#0057be 100%);
    background: -o-linear-gradient(top,  #1e5799 0%,#0057be 100%);
    background: -ms-linear-gradient(top,  #1e5799 0%,#0057be 100%);
    background: linear-gradient(to bottom,  #1e5799 0%,#0057be 100%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1e5799', endColorstr='#0057be',GradientType=0 );
    background-size: 1px 100px;
    background-repeat: repeat-x;
    margin: 0 auto;
    overflow: hidden;
    padding: 20px;
    position: relative;
}

#inner .wrap {
    background: -moz-linear-gradient(top,  rgba(0,0,0,0.25) 0%, rgba(0,0,0,0) 45%);
    background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(0,0,0,0.25)), color-stop(45%,rgba(0,0,0,0)));
    background: -webkit-linear-gradient(top,  rgba(0,0,0,0.25) 0%,rgba(0,0,0,0) 45%);
    background: -o-linear-gradient(top,  rgba(0,0,0,0.25) 0%,rgba(0,0,0,0) 45%);
    background: -ms-linear-gradient(top,  rgba(0,0,0,0.25) 0%,rgba(0,0,0,0) 45%);
    background: linear-gradient(top,  rgba(0,0,0,0.25) 0%,rgba(0,0,0,0) 45%);
    filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#a6000000',endColorstr='#00000000',GradientType=0 );
    border-radius: 10px;
}

#content-sidebar-wrap {
    background: #fff;
    float: left;
    margin: 1em;
}

【问题讨论】:

  • 您要模拟的影子是image,也许使用该技术会更容易。
  • 感谢您指出这一点;我没有意识到这是个问题。
  • 我很确定这可以用 CSS 来完成,因为他们已经做了一些非常相似的事情 here。既然 CSS 可以做到,为什么还要使用图片?

标签: background-image gradient fade css


【解决方案1】:

试试这个可能会有帮助

DEMO

【讨论】:

  • 更好但仍然不完全存在,因为阴影不再消失:Box Shadow Needs To Fade
  • 尝试新的 DEMO,它与您想要的很接近
  • 感谢 Afshin,但我认为它不会以这种方式工作。 This article 在半透明渐变上使用白框阴影,但由于我的背景是双色调的,这不是一个选项。
猜你喜欢
  • 1970-01-01
  • 2011-04-12
  • 2014-04-22
  • 1970-01-01
  • 1970-01-01
  • 2012-07-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多