【问题标题】:Black and White background CSS [duplicate]黑白背景CSS [重复]
【发布时间】:2014-08-05 07:06:23
【问题描述】:

我在<body> 块上有一张背景图片。

我想使用 webkit-filter: grayscale(100%);

但是当我将此过滤器应用到正文块时,我网站上的所有图像也会变成黑白图像。我只希望我的背景是黑白的。我该怎么做?

【问题讨论】:

    标签: css background


    【解决方案1】:

    插入一个绝对定位的 div 并为其应用背景。

    <body>
    <div id="BG"></div>
    ....
    other code here
    ....
    </body>
    
    
    #BG{
       position:fixed;
       left:0;
       right:0;
       top:0;
       bottom:0;
       background-image:(yourimage);
       webkit-filter: grayscale(100%);
       z-index:-500;
    }
    

    小提琴:http://jsfiddle.net/m5d5w/6/

    不要忘记也为非 webkit 浏览器添加过滤器。看: Greyscale Background Css Images

    【讨论】:

    • 您需要为此设置 z-index 吗?图片会出现在哪里?文字背后?
    • 此解决方案将阻止此页面上的文本选择。
    • 我有固定的背景。如果我设置位置:绝对,背景将不会被固定..
    • 背景 div 上的 position:fixed 怎么样?
    • 谢谢!!帮助。位置:固定一切正常!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-04
    • 2013-07-31
    • 2019-12-13
    • 2021-04-20
    相关资源
    最近更新 更多