Setting background transparency and not effecting text inside

This question already has an answer here:

  • CSS opacity only to background color not the text on it? [duplicate] 11 answers

  • 在背景上使用rgba并在其中设置不透明度,因为它不会影响不透明度等孩子。

    #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>
    链接地址: http://www.djcxy.com/p/89346.html

    上一篇: CSS背景不透明

    下一篇: 设置背景透明度并且不影响文本内部