简体   繁体   English

调节CSS中子元素的不透明度

[英]regulating opacity of child elements in css

i am using a div named #search-container 我正在使用一个名为#search-container的div

i am using its opacity as 0.6. 我正在使用其不透明度为0.6。

so that it wud have some opacity 所以它会有些不透明

#search-container
                               {
                                border-radius: 15px;
                                moz-border-radius: 15px;

                                position:absolute;
                                height:45%; 
                                width:55%; 
                                left: 3%;top:30%; 
                                background-color: #000; 
                                opacity:0.6;  
                                }

now i am placing a text box under the search container having id #city 现在我在ID为#city的搜索容器下放置一个文本框

i am using a css for #city 我正在为#city使用CSS

#city
                                   {

                                    height:20%; 
                                    width:40%; 
                                    opacity:1;  
                                    }

but still, the text box is having an opacity equal to the search-container 但是,文本框的不透明度等于搜索容器

it seems the child is having same opacity as of its residing parent 似乎孩子和住家的孩子有相同的不透明度

how can i make the text box look solid, i want the div #search-container to be opaque, but the text box should be solid.. 我怎样才能使文本框看起来牢固,我希望div#search-container不透明,但是文本框应该是牢固的。

is there any way to achieve this??? 有什么办法可以实现这一目标???

some help will be appreciable... thanks in advance... 一些帮助将是可观的...在此先感谢...

CSS element opacity is multiplied down through child elements so if I were to have a 50% opacity red div inside a 50% opacity black div on top of a white background, I would be able to see some black through the red and white through the whole thing. CSS元素的不透明度会通过子元素相乘,因此,如果我要在白色背景顶部的50%不透明度黑色div中有一个50%不透明度的红色div,我将能够看到红色和白色之间的黑色整件事。

If you only need background colour opacity, you can use rgba() as a background to get around this but it's not supported by IE6-. 如果只需要背景颜色不透明度,则可以使用rgba()作为背景来解决此问题,但IE6-不支持。 Background image/image opacity can be done using PNG or SVG images. 可以使用PNG或SVG图像完成背景图像/图像不透明度。 If you absolutely need full element opacity then you can also use a wrapper div to make the semi-transparent element and the opaque element siblings and use absolute positioning ( yuck ). 如果您绝对需要完全不透明的元素,那么还可以使用wrapper div来使半透明元素和不透明元素成为同级元素,并使用绝对定位( yuck )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM