红色 bg +黑色区域,不透明度为 85 = 粉红色文本
<style>
* {
background: red;
}
.blackbalk{
background:black;
ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=85)";
filter:alpha(opacity=85);
-khtml-opacity:.85;
-moz-opacity:.85;
opacity:.85;
width: 985px;
margin: 0 auto;
height:255px;
color: white;
}
</style>
<div class="blackbalk">Text </div>
现在我的文字变成粉红色,为什么? 怎样才能让它再次变白呢?
问候
编辑:JS Fiddle 说清楚: http://jsfiddle.net/WFxbH/
<style>
* {
background: red;
}
.blackbalk{
background:black;
ms-filter: "progid:DXImageTransform.Microsoft.Alpha(Opacity=85)";
filter:alpha(opacity=85);
-khtml-opacity:.85;
-moz-opacity:.85;
opacity:.85;
width: 985px;
margin: 0 auto;
height:255px;
color: white;
}
</style>
<div class="blackbalk">Text </div>
Now my text gets pink, why?
How can i get it white again?
Greetings
Edit: JS Fiddle to make it clear: http://jsfiddle.net/WFxbH/
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过在元素上使用
rgba
背景来实现:现场演示 - 这将在"中工作你关心的每个浏览器”,我的 jsFiddle 包含推荐的 IE 条件注释 使其也可以在该浏览器中工作。
You can do it by instead using an
rgba
background on your element:Live Demo - this will work "in every browser you care about", and my jsFiddle includes the recommended IE conditional comment to make it also work in that browser.
嗯,不透明度影响整个元素及其内容,而不仅仅是背景颜色。如果您只想将背景颜色设置为 85% 黑色,则应该使用 RGBA 颜色来指定它,如下所示:
Thew, opacity affects the entire element and its contents, not just the background color. If you just want the background color to be 85% black, you should specifiy it with an RGBA color, like so:
编辑:无法克服不透明度的级联。我的最佳选择是使用单像素 85% 不透明度黑色 png 作为背景图像。选项 2 是让内部内容实际上位于 div 之外,然后将其放置在上面,但这要挑剔得多。您甚至可以让透明 png 在 IE 中工作,而不需要太多麻烦。
忽略:不是积极的,因为我现在无法测试它,但我认为文本随着不透明度的变化而变得半透明。也许如果您将文本放在背景颜色:无和颜色:白色的范围内;也许可以解决。可能必须将跨度不透明度设置为 100% 才能覆盖。
EDIT: cant over ride the cascading of opacity. Best alternative in my pinion is to use a single pixel 85% opacity black png as the background image. option 2 would be to make the inner content actually outside of the div then position it over but that's a lot finickier. You can even get the transparent png to work in IE without much trouble.
IGNORE:Not positive, as I can't test it right now but I assume the text is becoming translucent with the opacity change. Perhaps if you put your text inside a span with background-color:none and color:white; it might work it out. May have to set the spans opacity to 100% to override.