如何为子元素设置html5 Web过滤器?

时间:2013-08-14 17:31:45

标签: html5 css3

如何为子元素设置html5 web过滤器? 在我的情况下,我想看到亮度为1的子元素的图像(因此,如果没有应用滤镜,图像将处于原始状态)

这是一个样本 http://jsfiddle.net/sMCfP/1/

div.scena
{
  width:400px;
  height:400px;
  background:url(http://www.w3schools.com/css/klematis2.jpg) repeat;
  border:1px solid black;
  -webkit-filter: brightness(0.3);
}

div.snippet
{
  border:2px solid black;
  width:200px;
  height:200px;
  border:1px solid black;
  opacity:1
  -webkit-filter: brightness(1.7) !important;
}

<div class="scena">
  <p>this is scena</p>
  <div class="snippet">
    <img src="http://www.w3schools.com/css/klematis2.jpg" alt="Smiley face" height="142" width="142">
  </div>
</div>

知道该怎么做吗?

您是否知道使用css3采用不同方法的任何类似解决方案?我只针对webkit。

建议

解决方案,稍作修改:

http://jsfiddle.net/sMCfP/7/

2 个答案:

答案 0 :(得分:1)

你必须将效果添加到img本身:

http://jsfiddle.net/sMCfP/2/

div.snippet img {
   -webkit-filter: brightness(1.7) !important;
}

答案 1 :(得分:1)

一种方法是在包装器中包含两个div,并使它们成为兄弟姐妹:

jsFiddle(需要更多布局,但应该给你一个想法)

更多信息:CSS Opacity That Doesn’t Affect Child Elements

<强> HTML

<div class="wrapper">
    <div class="scena">
        <p>this is scena</p>
    </div>
    <div class="snippet">
        <img src="http://www.w3schools.com/css/klematis2.jpg" alt="Smiley face" height="142" width="142">
    </div>
</div>

<强> CSS

div.wrapper {
    width:400px;
    height:400px;
}
div.scena {
    position: absolute;
    top: 0;
    left: 0;
    width:400px;
    height:400px;
    background:url(http://www.w3schools.com/css/klematis2.jpg) repeat;
    border:1px solid black;
    -webkit-filter: brightness(0.3);
}
div.snippet {
    position: absolute;
    top: 0;
    left: 0;
    border:2px solid black;
    width:200px;
    height:200px;
    border:1px solid black;
    opacity:1;
    -webkit-filter: brightness(1.7) !important;
}