【发布时间】:2017-03-17 00:40:11
【问题描述】:
我正在尝试仅使用 CSS(没有 svg) 创建粘糊糊的效果。
一切正常,但我的父容器有一个 contrast filter,我不能在我的子元素上使用颜色(对比度过滤器会改变颜色)。
是否有人知道一种基本方法可以仅使用 CSS 或反转对比度过滤器以在子元素上获得正确的颜色?
我的代码:
body{
background: #fff;
}
.blobs {
position:absolute;
top:0;
left:0;
bottom:0;
right:0;
background: #fff;
width:400px;
height:200px;
margin:auto;
filter:contrast(20);
-webkit-filter:contrast(20);
}
.blob {
background:black;
width:100px;
height:100px;
position:absolute;
left:50%;
top:50%;
margin-top:-50px;
margin-left:-50px;
border-radius:100%;
transition: cubic-bezier(0.82, 0.1, 0.24, 0.99) 2.5s;
-webkit-transition: cubic-bezier(0.82, 0.1, 0.24, 0.99) 2.5s;
box-shadow: 0 0 30px 10px black;
}
.blobs:hover .blob:first-child {
transform:translateX(-70px);
}
.blobs:hover .blob:last-child {
transform:translateX(70px);
}
<div class="blobs">
<div class="blob"></div>
<div class="blob"></div>
</div>
当我为子元素着色时:
body{
background: #fff;
}
.blobs {
position:absolute;
top:0;
left:0;
bottom:0;
right:0;
background: #fff;
width:400px;
height:200px;
margin:auto;
filter:contrast(20);
-webkit-filter:contrast(20);
}
.blob {
background: rgb(255, 113, 93);
width:100px;
height:100px;
position:absolute;
left:50%;
top:50%;
margin-top:-50px;
margin-left:-50px;
border-radius:100%;
transition: cubic-bezier(0.82, 0.1, 0.24, 0.99) 2.5s;
-webkit-transition: cubic-bezier(0.82, 0.1, 0.24, 0.99) 2.5s;
box-shadow: 0 0 30px 10px rgb(255, 113, 93);
}
.blobs:hover .blob:first-child {
transform:translateX(-70px);
}
.blobs:hover .blob:last-child {
transform:translateX(70px);
}
.original-color {
height: 100px;
background: rgb(255, 113, 93);
}
<div class="blobs">
<div class="blob"></div>
<div class="blob"></div>
</div>
<div class="original-color"></div>
【问题讨论】:
-
嗨@RedBreast,不幸的是它不是。在您的示例中,颜色会发生变化,因为父级上的对比度过滤器。我正在为这种行为寻找解决方案,并使子元素具有正确的颜色。将您的红色更改为绿色,您就会发现问题
-
对不起,我帮不上忙,但这真的很酷:P
标签: css css-filters