重置具有一些不透明度的元素的子元素的不透明度

时间:2013-02-23 08:03:31

标签: html css

我不希望子元素继承父不透明度。 [在此输入链接描述] [1]

[1]:http://jsfiddle.net/xALAW/ jsfiddle

<html>

    <head></head>
    <body>

        <div class='hasopacity'>
            This is the text with some opacity
            <div class='noopacity'>
                This is the text with no opacity 
            </div>
        </div>
</body>

CSS

.hasopacity{opacity:0.5}
.noopacity{opacity:1}

2 个答案:

答案 0 :(得分:2)

子元素必须继承父级的不透明度设置。

我所知道的唯一解决方案是让通常是孩子的元素实际上是一个兄弟元素,它被定位为看起来像是一个子元素。

答案 1 :(得分:1)

你不能,这是因为你正在制作透明的东西,如果里面有其他东西,它也会透明!

无论如何,这是一个重复的问题:I do not want to inherit the child opacity from the parent in CSS

相关问题