2017-05-09 44 views
0

我想使用濾鏡:亮度將div的背景圖像變暗。它運作良好,但顯然它會使整個div變暗,而不僅僅是圖像。我如何才能使用CSS變暗背景圖像?我想有一些白色的文字。背景:網址和濾鏡:亮度

這裏是我的代碼:

#about_header { 
 
    background: url(../img/background/spa_02.jpg) no-repeat center center fixed; 
 
filter: brightness(20%); 
 
-webkit-filter: brightness(20%); 
 
-moz-filter: brightness(20%); 
 
-o-filter: brightness(20%); 
 
-ms-filter: brightness(20%); 
 
    height:400px; 
 
    display: table; 
 
    position: relative; 
 
    width: 100%; 
 
    -webkit-background-size: cover; 
 
    -moz-background-size: cover; 
 
    -o-background-size: cover; 
 
    background-size: cover; 
 
} 
 

 
#about_header h1{ 
 
    color: white; 
 
}
<section id="about_header"> 
 
    <div class="container text-vcenter"> 
 
    <div class="row"> 
 
     <div class="col-sm-12"> 
 
     <div> 
 
      <h1>Contact us</h1> 
 
     </div> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</section>

+0

使用2個獨立的'div's,一個與背景和規模的父母,對方只包含的內容和延伸填補父母。 –

+0

我不明白,你能告訴我編輯我的代碼嗎?那麼,過濾器應該在哪裏? – Ishiru

回答

1

實際上,我是錯了,當我談到家長和孩子。你必須把容器的同一水平下:

#about_header { 
 
    background: url("http://www.thestatedhome.com/media/catalog/category/13514044-brown-natural-linen-texture-for-the-background-Stock-Photo.jpg") no-repeat center center fixed; 
 
    filter: brightness(20%); 
 
    height: 400px; 
 
    position: relative; 
 
    width: 100%; 
 
    background-size: cover; 
 
} 
 

 
.container { 
 
    display: table; 
 
    position: absolute; 
 
    top: 0px; 
 
    height: 400px; 
 
    width: 100%; 
 
} 
 

 
.text-vcenter { 
 
    display: table-cell; 
 
    text-align: center; 
 
    vertical-align: middle; 
 
} 
 

 
.container h1 { 
 
    color: white; 
 
}
<section id="about_header"></section> 
 
<div class="container"> 
 
    <div class="text-vcenter"> 
 
    <div class="row"> 
 
     <div class="col-sm-12"> 
 
     <div> 
 
      <h1>Contact us</h1> 
 
     </div> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</div>

+0

好的謝謝,我不明白如何用你以前的答案做到這一點。它運行良好,但現在我的文本中心donc工作了。 這是它的代碼:.text-vcenter {display:table-cell; text-align:center; vertical-align:middle; } – Ishiru

+0

@Ishiru我編輯了我的答案。 –

+0

現在沒事了。把它放在行上也行,但我更喜歡你的回答:)。謝謝你的幫助 :)。 – Ishiru