悬停图像文本叠加颜色问题

Hovered image text overlay color issues

过去几天我一直在学习 HTML 和 CSS,并制作了一些初学者页面。我试图在大图片上放置一个基本的悬停叠加层。悬停叠加层具有一些基本文本和图像上的低不透明度灰色填充。我的问题是我认为文本出现在叠加层后面。因此,文本似乎略微改变了颜色,从黑色变为白色不清晰等。我希望这更具体一些并符合指南。

body{
  background-color:#333;
  color:#fff;
  font-family:Arial, Helvetica, sans-serif;
  font-size:16px;
  line-height: 1.6em;
  margin:0;
}
.container{
  width:80%;
  margin:auto;
  overflow:hidden;
}
.pic{
  background-image: url(../images/desk.jpg);
  background-position: center ;
  min-height: 300px;
  margin-bottom:30px;
  text-align: center ;
}
.pic:hover{
  opacity:0.3;
  filter: alpha(opacity=30);
  transition: .5s ease;
}

.text{
  padding-top:110px;
  color:#fff;
  opacity:0;
  position: relative;
  text-align: center;
}
.pic:hover .text{
     opacity:0.6;
     text-align: center;
     font-size:20px;
     font-weight:700;
     font-family:Arial, Times, serif;
     padding-top:110px;
     transition: .5s ease;

     color:#fff;
}
#main-header{
  background-color:#000;
  color:#fff;
  padding:10;

}
#nav-bar{
  background-color:#000;
  color:#fff;

}

#nav-bar ul{
  padding:10;
  list-style: none;

}

#nav-bar li{
  display: inline;

}

#nav-bar a{
  color:#fff;
  text-decoration: none;
  font-size:18px;
  padding-right:15px;

}

#nav-bar a: hover{
  color: #coral;
}
#showcase{
  background-image: url(../images/showcase.jpg);
  background-position: center right;
  min-height: 300px;
  margin-bottom:30px;
  text-align: center ;
}
#showcase h1{
  color: #fff;
  font-size: 50px;
  line-height: 1.6em;
  padding-top: 30px;
}
  <header id="main-header">
    <div class="container">
      <h1>SHAYMAC</h1>
    </div>
  </header>
  <nav id="nav-bar">
    <div class="container">
      <ul>
        <li><a href="https://www.google.com/">home</a> </li>
        <li><a href="#">about</a> </li>
        <li><a href="#">service</a> </li>
      </ul>
    </div>
  </nav>

  <div class="pic">
      <div class="text"><p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod</p></div>
  </div>

你写的是正确的,当你将鼠标悬停在你写的图像上时,你想要有一个不透明度并且它还将文本嵌入其中,因为 textpic class.

您可以将另一个 div 包裹在图像之上以仅显示 img

有几个选项可以处理它,但我将通过更改背景颜色而不是文本颜色向您展示其中一种方法:

.pic:hover{
  background: rgba(0, 0, 0, 0.4);
  filter: alpha(opacity=30);
  transition: .5s ease;
}

这只是一个例子,理解我的意思。

body {
  background-color: #333;
  color: #fff;
  font-family: Arial, Helvetica, sans-serif;
  font-size: 16px;
  line-height: 1.6em;
  margin: 0;
}

.container {
  width: 80%;
  margin: auto;
  overflow: hidden;
}

#forImg {
  background-image: url(http://placekitten.com/301/301);
}

.pic {
  background-position: center;
  min-height: 300px;
  margin-bottom: 30px;
  text-align: center;
}

.pic:hover {
  background: rgba(0, 0, 0, 0);
  filter: alpha(opacity=30);
  transition: .5s ease;
}

.text {
  padding-top: 110px;
  color: #fff;
  opacity: 0;
  position: relative;
  text-align: center;
}

.pic:hover .text {
  opacity: 0.6;
  text-align: center;
  font-size: 20px;
  font-weight: 700;
  font-family: Arial, Times, serif;
  padding-top: 110px;
  transition: .5s ease;
  color: #fff;
}

#main-header {
  background-color: #000;
  color: #fff;
  padding: 10;
}

#nav-bar {
  background-color: #000;
  color: #fff;
}

#nav-bar ul {
  padding: 10;
  list-style: none;
}

#nav-bar li {
  display: inline;
}

#nav-bar a {
  color: #fff;
  text-decoration: none;
  font-size: 18px;
  padding-right: 15px;
}

#nav-bar a: hover {
  color: #coral;
}

#showcase {
  background-image: url(../images/showcase.jpg);
  background-position: center right;
  min-height: 300px;
  margin-bottom: 30px;
  text-align: center;
}

#showcase h1 {
  color: #fff;
  font-size: 50px;
  line-height: 1.6em;
  padding-top: 30px;
}
<body>
  <header id="main-header">
    <div class="container">
      <h1>SHAYMAC</h1>
    </div>
  </header>
  <nav id="nav-bar">
    <div class="container">
      <ul>
        <li><a href="https://www.google.com/">home</a> </li>
        <li><a href="#">about</a> </li>
        <li><a href="#">service</a> </li>
      </ul>
    </div>
  </nav>
  <div id="forImg">
    <div class="pic">
      <div class="text">
        <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod</p>
      </div>
    </div>
  </div>
  <footer>

  </footer>

</body>