【问题标题】:Partially apply css image filter部分应用 css 图像过滤器
【发布时间】:2014-03-07 05:05:27
【问题描述】:

我想要做的是将 css 过滤器部分应用于带有背景大小封面的背景图像。看看http://jsfiddle.net/vFYFz/

<div id="grandparent">
    <div id="parent">
        <div id="child"></div>
    </div>
</div>

<div id="original">
</div>

#original {
    position: fixed;
    width: 100%; height: 100%;
    background-image: url('http://userserveak.last.fm/serve/_/96476693/Natural+Mystic+JPG.jpg');
    background-size: cover;
}

#grandparent {
    position: absolute;
    width: 33%; height: 100%;
    overflow-x: hidden;
    z-index: 1;
}

#parent {
    position: fixed;
    width: 100%; height: 100%;
}

#child {
    position: absolute;
    width: 100%; height: 100%;
    background-image: url('http://userserve-ak.last.fm/serve/_/96476693/Natural+Mystic+JPG.jpg');
    background-size: cover;
    -moz-filter: invert(100%);
    -webkit-filter: invert(100%);
    -o-filter: invert(100%);
    -ms-filter: invert(100%);
    filter: invert(100%);
}

过滤后的图像需要具有视口的宽度,以便跟随与原始相同的背景大小封面,所以我将它放在一个 100% 宽度的固定元素内。我希望它服从其祖父绝对元素的溢出,以便我可以将过滤器仅应用于图像的左侧 33%,但这不起作用。有什么想法可以解决这个问题吗?

【问题讨论】:

    标签: css


    【解决方案1】:

    如果我理解正确,你想切换“祖父母”和“父母”的位置:JS Fiddle

    #grandparent {
        position: fixed;
        width: 33%; height: 100%;
        overflow-x: hidden;
        z-index: 1;
    }
    
    #parent {
        position: absolute;
        width: 100%; height: 100%;
    }
    

    【讨论】:

    • 谢谢,我实际上是想让过滤后的图像与原始图像具有相同的比例。 IE。有一个背景图像,其大小为覆盖,其中仅过滤了左侧 33% 的图像。
    • 现在我只是将固定的父宽度设为 33%,将子宽度设为 300%。见:jsfiddle.net/vFYFz/2
    猜你喜欢
    • 2013-08-15
    • 2015-07-20
    • 2021-04-08
    • 2016-08-15
    • 2015-06-17
    • 1970-01-01
    • 2021-11-11
    相关资源
    最近更新 更多