目录

操作方法 - 图片上的文本块


了解如何在图片上放置文本块。


图片文本块

Norway

自然

多么美丽的日出

自然

多么美丽的日出

亲自试一试 »


如何在图片中放置文本块

步骤1)添加HTML:

示例

<div class="container">
  <img src="nature.jpg" alt="Norway" style="width:100%;">
  <div class="text-block">
    <h4>Nature</h4>
    <p>What a beautiful sunrise</p>
  </div>
</div>

步骤2)添加CSS:

示例

/* Container holding the image and the text */
.container {
  position: relative;
}

/* Bottom right text */
.text-block {
  position: absolute;
  bottom: 20px;
  right: 20px;
  background-color: black;
  color: white;
  padding-left: 20px;
  padding-right: 20px;
}
亲自试一试 »

要了解有关如何设置图片样式的更多信息,请阅读我们的CSS 图片教程。

要了解有关 CSS 定位的更多信息,请阅读我们的CSS 位置教程。