2017-06-07 2 views
2

Ich weiß nicht, wie background-image Opazität 0,5 und den Inhalt in voller Opazität zu machen.Wie ändert man die Deckkraft des Hintergrunds, ohne den Inhalt zu ändern?

.about-section { 
 
    height: 100%; 
 
    padding-top: 50px; 
 
    text-align: center; 
 
    /*background: #eee;*/ 
 
    background: url(../images/about.jpg); 
 
    background-repeat: no-repeat; 
 
    background-size: contain; 
 
    background-position: center; 
 
    opacity: 0.3; 
 
}
<section id="about" class="about-section"> 
 
    <div class="container"> 
 
    <div class="row"> 
 
     <div class="col-lg-12"> 
 
     <h1 class="head">About Us</h1> 
 

 
     </div> 
 
    </div> 
 
    </div> 
 
</section>

+0

https://stackoverflow.com/questions/44398224/set -background-image-with-transparent-color-und-auch-machen-die-Höhe-der-imag/44398374 # 4439 8374 – tech2017

+0

Sie können nicht mit CSS, wäre –

+0

Die beste Lösung, die ein halbtransparentes Bild verwenden, um einfach Ihr Bild zu ändern transparenter zu sein. Abgesehen davon können Sie versuchen, das Bild als separates Element zu behalten. – gaynorvader

Antwort

2

Ist dies die Art der Sache, nachdem Sie sind?

.about-section { 
 
    height: 100%; 
 
    padding-top: 50px; 
 
    text-align: center; 
 
    } 
 
    
 
    .background { 
 
    height: 100%; 
 
    width: 100%; 
 
    position: absolute; 
 
    background: url(https://ichef-1.bbci.co.uk/news/976/media/images/83351000/jpg/_83351965_explorer273lincolnshirewoldssouthpicturebynicholassilkstone.jpg); 
 
    background-repeat: no-repeat; 
 
    background-size: contain; 
 
    background-position: center; 
 
    opacity: 0.3; 
 
    
 
    }
<section id="about" class="about-section"> 
 
    <div class="background"> 
 
    </div> 
 
    <div class="container"> 
 
    <div class="row"> 
 
     <div class="col-lg-12"> 
 
     <h1 class="head">About Us</h1> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</section>

+1

Es funktioniert, thank u so much :) –

+0

Keine Sorge @ Y.EzzEldin – dennispreston

0

Für den Moment hat CSS diese Möglichkeit nicht bieten (es sei denn, Ihr Hintergrund nur eine Farbe ist, in welchem ​​Fall Sie rgba() verwenden können).

Um dies zu erreichen, können Sie Ihr .about-section in position: relative; platzieren und ein <div> Inneres schaffen (vorzugsweise als erstes Kind, oder noch besser, als ::before Pseudoelement) absolut positioniert ist, mit voller Breite und Höhe. Sie können dann die Deckkraft wie gewünscht anpassen, ohne den Inhalt zu beeinflussen.

1

Sie die ::before "-Pseudoelement verwenden können.

.about-section { 
 
    position:relative; /* Notice this */ 
 
    height: 100%; 
 
    padding-top: 50px; 
 
    text-align: center; 
 
} 
 

 
.about-section::before { 
 
    content:''; 
 
    position:absolute; 
 
    width:100%; 
 
    height:100%; 
 
    left:0px; 
 
    top:0px; 
 
    background: #000; /* change to whatever you want */ 
 
    opacity:0.3; 
 
}
<section id="about" class="about-section"> 
 
    <div class="container"> 
 
    <div class="row"> 
 
     <div class="col-lg-12"> 
 
     <h1 class="head">About Us</h1> 
 
     </div> 
 
    </div> 
 
    </div> 
 
</section>

1

können Sie Pseudo-Elemente verwenden, um es zu erhalten wie folgt

.about-section { 
 
    height: 100%; 
 
    padding-top: 50px; 
 
    text-align: center; 
 
    /*background: #eee;*/ 
 
    background: url(http://lorempixel.com/400/200/); 
 
    background-repeat: no-repeat; 
 
    background-size: contain; 
 
    background-position: center; 
 
    position: relative; 
 
} 
 

 
.about-section::after { 
 
    content: ''; 
 
    height: 100%; 
 
    width: 100%; 
 
    background: rgba(255, 255, 255, 0.5); /*Change as your need */ 
 
    position: absolute; 
 
    top: 0; 
 
    left: 0; 
 
    z-index: 1; 
 
}
<section id="about" class="about-section"> 
 
    <div class="container"> 
 
    <div class="row"> 
 
     <div class="col-lg-12"> 
 
     <h1 class="head">About Us</h1> 
 

 
     </div> 
 
    </div> 
 
    </div> 
 
</section>

Verwandte Themen