How to position text over an image in css

后端 未结 7 979
囚心锁ツ
囚心锁ツ 2020-11-22 03:38

How do I center a text over an image in css?

7条回答
  •  执笔经年
    2020-11-22 04:29

    as of 2017 this is more responsive and worked for me. This is for putting text inside vs over, like a badge. instead of the number 8, I had a variable to pull data from a database.

    this code started with Kailas's answer up above

    https://jsfiddle.net/jim54729/memmu2wb/3/

    My HTML

    8

    and my css:

    .containerBox {
      position: relative;
      display: inline-block;
    }
    
    .text-box {
      position: absolute;
      height: 30%;
      text-align: center;
      width: 100%;
      margin: auto;
      top: 0;
      bottom: 0;
      right: 0;
      left: 0;
      font-size: 30px;
    }
    
    .img-responsive {
      display: block;
      max-width: 100%;
      height: 120px;
      margin: auto;
      padding: auto;
    }
    
    .dataNumber {
      margin-top: auto;
    }
    

提交回复
热议问题