使用 CSS 的 'background-image' 属性将图片作为文本的背景,示例如下:

HTML 代码:

<div class='text-bg'>这是一段文本,图片作为背景</div>

CSS 代码:

.text-bg {
  background-image: url('image.jpg');
  background-repeat: no-repeat;
  background-position: center center;
  background-size: cover;
  color: #fff;
  padding: 20px;
}

解析:

  • 'background-image' 属性指定背景图片的 URL 地址。
  • 'background-repeat' 属性指定背景图片是否重复,默认为 'repeat'。
  • 'background-position' 属性指定背景图片的位置,默认为左上角。
  • 'background-size' 属性指定背景图片的大小,默认为 'auto'。
  • 'color' 属性指定文本的颜色。
  • 'padding' 属性指定文本的内边距。
HTML 使用图片作为文本背景 - CSS background-image 属性

原文地址: https://www.cveoy.top/t/topic/oqKk 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录