【问题标题】:Background Image Fill on div with gradient背景图像用渐变填充div
【发布时间】:2013-12-25 16:24:13
【问题描述】:

以下是我的小提琴,我试图将背景图像(位置居中)放到宽度设置为 100% 的 div 中,如果图像的背景宽度为 20px 并且用户屏幕为 100px,那么我想要图像不会拉伸宽度,模糊渐变部分会填充图像左右部分的区域。请告诉我该怎么做?

http://jsfiddle.net/R6K5S/

#background {
  /* fallback */
  background-color: #2F2727;
  background-image: url(http://farm5.staticflickr.com/4004/4335972718_a491a3076d.jpgimages/radial_bg.png);
  background-position: center center;
  background-repeat: no-repeat;
    width:100%;
        height:250px;

  /* Safari 4-5, Chrome 1-9 */
  /* Can't specify a percentage size? Laaaaaame. */
  background: -webkit-gradient(radial, center center, 0, center center, 460, from(#1a82f7), to(#2F2727));

  /* Safari 5.1+, Chrome 10+ */
  background: -webkit-radial-gradient(circle, #1a82f7, #2F2727);

  /* Firefox 3.6+ */
  background: -moz-radial-gradient(circle, #1a82f7, #2F2727);

  /* IE 10 */
  background: -ms-radial-gradient(circle, #1a82f7, #2F2727);

  /* Opera couldn't do radial gradients, then at some point they started supporting the -webkit- syntax, how it kinda does but it's kinda broken (doesn't do sizing) */
}

【问题讨论】:

  • 你的头像坏了
  • @Kirk 使用你喜欢的任何 xyz 图像我只是想知道如何在图像周围填充。
  • 据我所知。无论宽度如何,您都希望图像居中?

标签: html css


【解决方案1】:

据我了解,这是您要求的,请将其添加到 background 类中

box-shadow: inset 0 10px 10px 10px rgba(255,255,255,1);

使用上面的线使其模糊边框,这实际上是一个简单的技巧。不透明是白色的模糊边框,请针对所有浏览器进行优化。

.imageclass{
    position:absolute;
    top:50%;
    left:50%;
}

#background {
    background-color: #2F2727;
    background-image: url(http://farm5.staticflickr.com/4004/4335972718_a491a3076d.jpgimages/radial_bg.png);
    background-position: center center;
    background-repeat: no-repeat;
    width:100%;
    height:250px;
    background: -webkit-gradient(radial, center center, 0, center center, 460, from(#1a82f7), to(#2F2727));
    background: -webkit-radial-gradient(circle, #1a82f7, #2F2727);
    background: -moz-radial-gradient(circle, #1a82f7, #2F2727);
    background: -ms-radial-gradient(circle, #1a82f7, #2F2727);
    box-shadow: inset 0 10px 10px 10px rgba(255,255,255,1); // Here you asked for blurry Edge
}
<div id="background">
    <img class="imageclass" src="http://www.topcoder.com/wp-content/themes/tc-eoi-theme-v3.2/i/rss-small.png"/>   
</div>

    

【讨论】:

  • 请告诉我如何创建边缘模糊的渐变?
  • 实际上我想我没有很好地解释我的问题,我一直想说的是,当我用作背景的图像宽度以用户屏幕的 100% 屏幕尺寸结束时,然后模糊endges 出现在剩余的 div 背景上,就像你使用 background-image: url(IMAGEURL), -ms-radial-gradient(center, ellipse cover, rgba(237,237,237,1) 0%, rgba(237,237,237,1) 0%, rgba(102,102,102,1) 100%);
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-10
  • 2016-05-28
  • 2020-11-19
  • 1970-01-01
  • 2016-02-12
  • 2019-01-28
相关资源
最近更新 更多