Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

CSS

Kenny Parewijck
Kenny Parewijck
4,602 Points

background shade shades not only the background..

Hi!

I am having troubles with a background shade. i would like to add a black background to my div container that wrappes the logo and nav. Then I would like to add an opacity so that the background fades into a black simpel light blur and the background images comes true.

For some reason the opacity property shades everyting in my wrapping logo nav container..

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Instashoot</title>
    <link rel="stylesheet" href="normalize.css">
    <!-- Hier komen de fonts -->
    <link rel="stylesheet" href="main.css">
    <link rel="stylesheet" href="responsive.css">
  </head>
  <body>

    <div class="main-header">
        <div class="container-logo-nav">
            <img class="logo" src="images/logo-02.png" alt="" />
            <div class="nav">
              <ul class="nav-ul">
                <li>Pricing</li>
                <li>Help</li>
              </ul>
            </div>
        </div>
        <div class="container-titles-ctas">
            <h1></h1>
            <p></p>
            <div class="ctas">
              <a href="#"></a>
              <a href="#"></a>
            </div>
        </div>
    </div>

    <div class="container-meer-weten">
        <div class="col-one">
          <h2></h2>
          <p></p>
        </div>
        <div class="col-two">
          <img src="" alt="" />
          <h3></h3>
          <p></p>
        </div>
        <div class="col-tree">
          <img src="" alt="" />
          <h3></h3>
          <p></p>
        </div>
        <div class="col-four">
          <img src="" alt="" />
          <h3></h3>
          <p></p>
        </div>
    </div>
  </body>
</html>
* {
  padding: 0;
  margin: 0;
  border: 0;
  box-sizing: border-box;
  font-family: sans-serif;
}

img {max-width: 100%;}

ul,ol,li {
  padding: 0;
  margin:0;
  border: 0;
  list-style: none;
}

.main-header {
  width: 100%;
  height: 710px;
  background-image: url(images/QIRDYNRF06.jpg);
  background-position: center;
  background-size: cover;
  background-repeat: no-repeat;
  padding: 0;
  margin: 0;
  border-top: 1px solid grey;
}

.container-logo-nav {
  background-color: black;
  opacity: 0.3;
}

.logo {
  max-width: 130px;
  padding: 0.3em;
  margin: 1em;
}

.nav {
  text-align: right;
  margin-right: 2em;
  margin-top: 1em;
  width: 30%;
  text-align: right;
  float: right;
}

.nav-ul li{
  display: inline-block;
  padding: 0.3em;
  margin-left: 0.6em;
  font-weight: bold;
  font-size: 0.85em;
  color: white;
}

2 Answers

Adam Hill
Adam Hill
7,492 Points

Opacity will affect the whole object and everything in it, you can use a semi-transparent background-color instead

.container-logo-nav {
  background-color: rgba(0,0,0,0.3);
}