在图像上放置文本

创建于 2024-12-03 / 25
字体: [默认] [大] [更大]

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


Image Text

Snow Bottom Left Top Left Top Right Bottom Right Centered

亲自试一试 »


如何在图片中放置文字

步骤 1) 添加 HTML:

实例

<div class="container">
  <img src="img_snow_wide.jpg" alt="Snow" style="width:100%;">
  <div class="bottom-left">Bottom Left</div>
  <div class="top-left">Top Left</div>
  <div class="top-right">Top Right</div>
  <div class="bottom-right">Bottom Right</div>
  <div class="centered">Centered</div>
</div>
步骤 2) 添加 CSS:

实例

/* 包含图像和文本的容器 */
.container {
  position: relative;
  text-align: center;
  color: white;
}

/* 左下角文字 */
.bottom-left {
  position: absolute;
  bottom: 8px;
  left: 16px;
}

/* 左上角文字 */
.top-left {
  position: absolute;
  top: 8px;
  left: 16px;
}

/* 右上角文字 */
.top-right {
  position: absolute;
  top: 8px;
  right: 16px;
}

/* 右下角文字 */
.bottom-right {
  position: absolute;
  bottom: 8px;
  right: 16px;
}

/* 居中文本 */
.centered {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
} 亲自试一试 »

要详细了解如何设置图片样式,请阅读我们的CSS 图片教程。

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



0 人点赞过