How to position text over an image in css

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

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

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 04:18

    How about something like this: http://jsfiddle.net/EgLKV/3/

    Its done by using position:absolute and z-index to place the text over the image.

    #container {
      height: 400px;
      width: 400px;
      position: relative;
    }
    #image {
      position: absolute;
      left: 0;
      top: 0;
    }
    #text {
      z-index: 100;
      position: absolute;
      color: white;
      font-size: 24px;
      font-weight: bold;
      left: 150px;
      top: 350px;
    }

    Hello World!

提交回复
热议问题