0

I am trying to get the title background of a site transparent but not the text within it:

#titlebackground {
     background-color: #333333;
     opacity: 0.5;
}
#title {
      font-family: Consolas, monaco, monospace;
      text-align: center;
      font-size: 9em;
      font-weight: 900;
      color: white;
      /*margin-top: -20%;*/
      display: inline-block;
      opacity: 1;
}
#titlelocation {
    position: relative;

}
        <div id="titlelocation">
          <div id="titlebackground">
            <span id="title">My title</span>
          </div>
   </div>

Setting the opacity of the span to 1 has no effect. How do I get the text to be fully seen but the background to be partially transparent?

David Tunnell
  • 7,252
  • 20
  • 66
  • 124

1 Answers1

3

Use rgba on the background and set the opacity there as it won't affect the children like opacity will.

#titlebackground {
  background-color: rgba(51,51,51,.5);
}
#title {
  font-family: Consolas, monaco, monospace;
  text-align: center;
  font-size: 9em;
  font-weight: 900;
  color: white;
  /*margin-top: -20%;*/
  display: inline-block;
}
#titlelocation {
  position: relative;
}
<div id="titlelocation">
  <div id="titlebackground">
    <span id="title">My title</span>
  </div>
</div>
j08691
  • 204,283
  • 31
  • 260
  • 272