html - 如何使用css在图片上方显示文字

标签 html css

我试图在图像上显示文字,但它对我不起作用 这是我的代码

 .banner{
          background-image: linear-gradient(rgba(0,0,0,.6),rgba(0,0,0,.6)),url(img/aboutus/s4.jpg);
          background-size: cover;
          background-attachment: scroll;
          background-repeat: no-repeat;
          height: 80vh;
          position: relative;
      }
      
      .img{
          position: absolute;
          left: 0;
          bottom: 0;
          width: 100%;
      }
     .info h5{
          position: absolute;
          z-index: 15;
          top: 0;
          left: 50%;
      }
    <section class="banner" >
        <div class="container">
            <div class="info">
                <h5>about us </h5>
            </div>
        </div>
        <img class="img" src="img/aboutus/home_overlay.png">
    </section>
  

结果显示无文字

enter image description here

如何解决这个问题 抱歉英语不好

最佳答案

这是一个非常简单的解决方案,格式最少,因此更容易编辑。

  .background {
    background: url(https://media.giphy.com/media/xTiTnxpQ3ghPiB2Hp6/giphy.gif) repeat;
    border: 2px solid black;
    height: 175px;
  }
  .info {
    padding-left: 20px;
    font-family: Arial;
    font-size: 20px;
    color: white;
  }
  <div class="background">
    <p class="info">About Us</p>
  </div>

关于html - 如何使用css在图片上方显示文字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54383124/

相关文章:

html - 动画 CSS 列和 SVG

html - 伪类的 CSS 问题

html - footer不能放到网站底部

CSS 和 MediaWiki - 使用绝对和相对 DIV 正确自动扩展 DIV

angularjs - 无法将图像放在中心

javascript - 在 ionic v1 中滚动到 div 时固定它

javascript - 如何在我的 html 代码中提供我在网上发现的 html 代码的引用文献?

javascript - 在 XML 文件中查找标签

html - 当图像大小改变时相对于图像定位文本

html - 标题中的 float 图像将标题推开