首页 > 解决方案 > 无法更改覆盖文本的颜色

问题描述

我在这个浪费的练习上花了几个小时。我无法将图像上的文本颜色设置为完美的白色。它呈现出它背后的颜色。请看一下。

@import url('https://fonts.googleapis.com/css2?family=Lato:wght@100;300;400;700;900&display=swap');
html {
  scroll-behavior: smooth;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow-x: auto;
  overflow-y: scroll;
  font-family: 'Lato';
}

header {
  background-color: #e8e9ea;
  padding: 10px 0;
}

.nav-container {
  width: 85%;
  margin: 0 auto;
}

nav {
  margin: 30px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.nav-top {
  margin: 15px 0;
}

.nav-brand {
  font-size: 1.8rem;
  font-weight: 300;
}

ul {
  list-style-type: none;
}

ul li {
  display: inline-block;
  margin: 0 8px;
  font-size: 14px;
  font-weight: 300;
}

li a {
  text-decoration: none;
  color: black;
}

.container {
  width: 85%;
  margin: 0 auto;
}

.mb_parallax_container {
  margin-top: 100px;
  height: 100vh;
  width: 100%;
  background-attachment: fixed;
  background-size: cover;
  background-repeat: no-repeat;
  background-image: url(https://i.ibb.co/q50nfZ1/Woman-visiting-psychologist-office-Patient-sitting-in-armchair-and-talking-to-psychiatrist-Vector-il.jpg);
  background-position: center;
  position: relative;
  z-index: 1;
}

.mb_parallax_overlay {
  height: 100vh;
  width: 100%;
  background-color: black;
  opacity: .4;
  display: flex;
  flex-flow: column;
  justify-content: center;
  align-items: center;
  position: relative;
  z-index: 2;
}

.mb_parallax_caption {
  text-align: center;
  width: 70%;
  position: relative;
  z-index: 3;
  opacity: 1;
  -webkit-user-select: none;
  /* Chrome all / Safari all */
  -moz-user-select: none;
  /* Firefox all */
  -ms-user-select: none;
  /* IE 10+ */
  user-select: none;
}

.mb_parallax_caption h1 {
  font-size: 5.5rem;
  color: white;
  margin: 20px 0;
}

.mb_parallax_caption p {
  margin: 20px 0;
  color: white;
  font-size: 1.6rem;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="style.css" />
  <title>Document</title>
</head>

<body>
  <header>
    <div class="nav-container">
      <div class="nav-top"></div>
      <hr>
      <nav>
        <h3 class="nav-brand">Hello Therapy</h3>
        <ul>
          <li><a href="#">Home</a></li>
          <li><a href="#">Therapist Repository</a></li>
          <li><a href="#">Crisis Intervention</a></li>
          <li><a href="#">Resources</a></li>
          <li><a href="#">Join Us</a></li>
          <li><a href="#">About</a></li>
          <li><a href="#">Blog</a></li>
          <li><a href="#">More</a></li>
        </ul>
      </nav>
    </div>
  </header>
  <div class="container">

    <div class="mb_parallax_container" id="mb_parallax_one">
      <div class="mb_parallax_overlay">
        <div class="mb_parallax_caption">
          <h1>Welcome to Hello Therapy</h1>
          <p>Making Therapy Accessible</p>
        </div>

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

</body>

</html>

如果有人能找到工作,那就太好了。提前致谢。

标签: htmlcss

解决方案


你已经opacity: 0.4设定了.mb_parallax_overlay,所有的孩子也都变黑了。在这种情况下,如果您的父母有 0.4,那么孩子的最大不透明度为 0.4(不透明度:孩子为 1)。

您可以尝试以下方法来使背景变暗。

.container {
  width: 85%;
  margin: 0 auto;
}

.mb_parallax_container {
  margin-top: 100px;
  height: 100vh;
  width: 100%;
  background-attachment: fixed;
  background-size: cover;
  background-repeat: no-repeat;
  background-image: url(https://i.ibb.co/q50nfZ1/Woman-visiting-psychologist-office-Patient-sitting-in-armchair-and-talking-to-psychiatrist-Vector-il.jpg);
  background-position: center;
  position: relative;
  z-index: 1;
}

.mb_parallax_overlay {
  height: 100vh;
  width: 100%;
  background-color: black;
  /*opacity: .4; remove this*/
  display: flex;
  flex-flow: column;
  justify-content: center;
  align-items: center;
  position: relative;
  z-index: 2;
  background: rgba(0, 0, 0, 0.5);
  /*darken background*/
}

.mb_parallax_caption {
  text-align: center;
  width: 70%;
  position: relative;
  z-index: 3;
  /*opacity: 1; not needed*/
  -webkit-user-select: none;
  /* Chrome all / Safari all */
  -moz-user-select: none;
  /* Firefox all */
  -ms-user-select: none;
  /* IE 10+ */
  user-select: none;
}

.mb_parallax_caption h1 {
  font-size: 5.5rem;
  color: white;
  margin: 20px 0;
}

.mb_parallax_caption p {
  margin: 20px 0;
  color: white;
  font-size: 1.6rem;
}
<div class="container">
  <div class="mb_parallax_container" id="mb_parallax_one">
    <div class="mb_parallax_overlay">
      <div class="mb_parallax_caption">
        <h1>Welcome to Hello Therapy</h1>
        <p>Making Therapy Accessible</p>
      </div>
    </div>
  </div>
</div>


推荐阅读