将非透明文本添加到半透明 div 容器中?

Adding non transparent text into semi transparent div container?

我正在尝试使用 <p> 标签在 4 个使用半透明标签的黑框内添加文本。我希望容器内的文本完全不透明。

根据我的阅读,我知道这是 CSS 的一个恼人的挫折。我看到了使用 rgba() 颜色作为背景或使用 .png 图像的选项。我在父容器上尝试了 rgba() 方法,但没有用。

我真的不想使用图像,因为图像文件大小会增加加载时间。我尝试过的一切都没有奏效。有人可以就如何处理这个问题给我一些建议吗?下面是我的代码。

.wrapper {
  position: relative;
  padding: 0 15px;
}

.responsive-image {
  width: 100%;
  height: auto;
}

#statement {
  position: absolute;
  text-align: center;
  top: 280px;
  left: 300px;
  font-size: 50px;
  font-weight: bold;
  color: #ffffff;
}

.opaque-box {
  position: absolute;
  top: 670px;
  left: 15px;
  background: #000000;
  opacity: 0.4;
  text-align: center;
  width: 25%;
  height: 30%;
  border-top: solid 2px #ffffff;
  border-bottom: solid 2px #ffffff;
}

p.box-content {
  padding-top: 50px;
  color: white;
  font-size: 20px;
  font-style: italic;
  font-weight: bold;
  position: relative;
}

.nav-item>a {
  color: #000000;
  font-weight: bold;
}

.nav-wrapper {
  position: absolute;
  right: 0;
  left: 0;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Mock Up</title>
  <!-- Custom CSS -->
  <link rel="stylesheet" type="text/css" href="css/style.css">
  <!-- Bootstrap Link -->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

<body>
  <div class="nav-wrapper">
    <nav class="navbar navbar-static-top">
      <!--Navbar-->
      <div class="container-fluid">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#mainNavBar">
             <!-- Collapsing Hamburger Buttons for mobile -->
             <span class="icon-bar"></span>
             <span class="icon-bar"></span>
             <span class="icon-bar"></span>
           </button>
        </div>
        <!--Menu Items-->
        <div class="collapse navbar-collapse navbar-right" id="mainNavBar">
          <ul class="nav navbar-nav">
            <li class="nav-item">
              <a href="#home">HOME</a>
            </li>
            <li class="nav-item">
              <a href="#showroom">SHOWROOM</a>
            </li>
            <li class="nav-item">
              <a href="#services">SERVICES</a>
            </li>
            <li class="nav-item">
              <a href="#info">INFO</a>
            </li>
            <li class="nav-item">
              <a href="#photos">PHOTO GALLERY</a>
            </li>
            <li class="nav-item">
              <a href="#contact">CONTACT</a>
            </li>
          </ul>
        </div>
      </div>
  </div>
  <div class="wrapper">
    <img class="responsive-image" src="https://lh3.google.com/u/1/d/0B0DSNKIQ7ncnRDNNQUgwWk1tVXc=w1366-h653-iv1">
  </div>
  </nav>
  <div class="opaque-box">
    <div>
      <p class="box-content">NEW <br>INVENTORY</p>
    </div>
  </div>
  <div class="boxes"></div>
  <div class="boxes"></div>
  <div class="boxes"></div>

  <script src="https://use.fontawesome.com/bd8b80bd9d.js"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>

</html>

这是我发现对我有用的方法。我不得不使用 top 和 left 属性将文本定向到下面是合适的解决方案的代码。我确信有一种更简洁的方法可以做到这一点,但我目前还不知道。

.wrapper {
 position: relative;
 padding: 0 15px;
}

.responsive-image {
 width: 100%;
 height: auto;
}

#statement {
 position: absolute;
 text-align: center;
 top: 280px;
 left: 300px;
 font-size: 50px;
 font-weight: bold;
 color: #ffffff;
}

.opaque-box {
 z-index: 1;
 position: absolute;
 top: 670px;
 left: 15px;
 background: #000000;
 opacity: 0.4;
 width: 325px;
 height: 197px;
 border-top: solid 2px #ffffff;
 border-bottom: solid 2px #ffffff;
}

.box-content {
 text-align: center;
 z-index: 2;
 padding-top: 50px;
 color: #ffffff;
 font-size: 20px;
 font-style: italic;
 font-weight: bold;
 position: relative;
 top: -380px;
 left: -500px;;
}

.nav-item > a {
 color: #000000;
 font-weight: bold;
}

.nav-wrapper {
  position:absolute;
  right: 0;
  left: 0;
}
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Mock Up</title>
    <!-- Custom CSS -->
    <link rel="stylesheet" type="text/css" href="css/style.css">
    <!-- Bootstrap Link -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
</head>

<body>
    <div class="nav-wrapper">
        <nav class="navbar navbar-static-top">
            <!--Navbar-->
            <div class="container-fluid">
                <div class="navbar-header">
                    <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#mainNavBar">
                        <!-- Collapsing Hamburger Buttons for mobile -->
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                        <span class="icon-bar"></span>
                    </button>
                </div>
                <!--Menu Items-->
                <div class="collapse navbar-collapse navbar-right" id="mainNavBar">
                    <ul class="nav navbar-nav">
                        <li class="nav-item">
                            <a href="#home">HOME</a>
                        </li>
                        <li class="nav-item">
                            <a href="#showroom">SHOWROOM</a>
                        </li>
                        <li class="nav-item">
                            <a href="#services">SERVICES</a>
                        </li>
                        <li  class="nav-item">
                         <a href="#info">INFO</a>
                        </li>
                        <li class="nav-item">
                         <a href="#photos">PHOTO GALLERY</a>
                        </li>
                        <li class="nav-item">
                         <a href="#contact">CONTACT</a>
                        </li>
                    </ul>
                </div>
            </div>
    </div>
    <div class="wrapper">

        <img class="responsive-image" src="https://lh3.google.com/u/1/d/0B0DSNKIQ7ncnRDNNQUgwWk1tVXc=w1366-h653-iv1">
    </div>
    </nav>
    <div class="opaque-box"></div>
    <a href="#new-inventory"><p class="box-content">NEW <br>INVENTORY</p></a>
    <div class="boxes"></div>
    <div class="boxes"></div>
    <div class="boxes"></div>

    <script src="https://use.fontawesome.com/bd8b80bd9d.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>

</html>