2013-10-23 114 views
1

我正在使用网站标题,我需要在标题的背景上放一些行。一旦我把它与一些不透明我得到一个问题。我所有的标题现在都处于不透明状态。CSS:问题与不透明

HTML:

<div class="header"> 
    <div clas="header strips"> 
    <div class="some_content"><lots of text</div> 
    </div> 
</div> 

CSS:

.header 
{ 
    height: 120px; 
    width: 100%; 
    float: left; 
    background-color: #3A5FCD; 
    background: linear-gradient(to bottom, #00BFFF,#3A5FCD); 
} 
.strips 
{ 
    background: url(../img/picture.png); 
    opacity: 0.3; 
} 
.some_content 
{ 
    color: #FFFFFF; 
    font-family: MaassslicerItalic; 
    font-size: 20pt; 
    border-bottom:5px solid red; 
} 

我不明白为什么我的<div class="some_content"><lots of text</div>也与透明度。

这里是链接到原始网站与RGBA背景颜色 http://portal.plazma.com.ua/

+0

[CSS透明度和子元素]的可能重复(http://stackoverflow.com/questions/2561460/css-opacity-and-child-elements) – showdev

回答

2

子元素始终继承父的不透明度。

,所以你需要给不透明这样rgba(0,0,0,0.3)

background: rgba(0,0,0,0.3) url(picture.png); 

RGBA ==> a代表阿尔法

尝试一下本作的背景图像

.element { 
     background: url(picture.png); 

     background-color: rgba(0,0,0,0.5); 

    } 
1

工作。

像这样:background-color: rgba(255,255,255,0.3)最后一个数字(0.3)是您指定的RGB颜色的不透明度。

或简称:

background: rgba(255,255,255,0.3) url(../img/picture.png); 
+0

但当时它并没有显示从 我的图片背景:url(../ img/picture.png); – myrko

+0

@myrko然后使用背景颜色。看我的编辑。 –

1

您可以使用背景 - CSS中的颜色不透明与图像结合在一起。

.strips 
{ 
    background: rgba(0,0,0,0.3) url(../img/picture.png); 
} 
+0

但图片网址(../ img/picture.png);必须在不透明度下 – myrko

+0

你能直接在png中设置不透明度吗? –