css 文字区域根据图片形状显示,根据文字设置背景图

css文字区域根据图片形状.

通过css的图像遮罩 mask-image 去设置

效果

完整代码

复制代码
<template>
	<view class="box">
		<view class="box-text text-white">
			Preferred<br>by the Pros!
		</view>
	</view>
</template>

<style scoped lang="scss">
.text-white {
		color: #000;
		-webkit-mask-image: url(@/static/stroke_img1_red.png);
		mask-image: url(@/static/stroke_img1_red.png);
		mask-size: contain;
		mask-repeat: no-repeat;
		mask-position: center;
		z-index: 3;
	}
</style>

css设置文字背景图

效果

文字设置透明

color: transparent;

背景图裁剪进文字

-webkit-background-clip: text;

background-clip: text;

完整代码

复制代码
<template>
  <!-- 文字背景图效果 -->
  <view class="page-container">
    <view class="text-image">Preferred<br>by the Pros!</view>
  </view>
</template>

<script>
/* 这是一个标准的 UniApp 页面,直接复制到 pages 目录即可使用 */
export default {
  name: "TextBgImage",
  data() {
    return {};
  },
};
</script>

<style scoped>
/* 页面容器 */
.page-container {
  padding: 60rpx 0;
  display: flex;
  justify-content: center;
  align-items: center;
  
}

/* 核心:文字背景图样式 */
.text-image {
  font-size: 70rpx;
  font-weight: bold;
  /* 文字颜色透明 */
  color: transparent;
  /* 背景图(可以换成本地图片 /static/xxx.png) */
  background-image: url("@/static/stroke_img1_red.png");
  background-size: cover;
  background-position: center;
  
  /* 兼容所有 UniApp 平台的核心写法 */
  -webkit-background-clip: text;
  background-clip: text;
}
</style>
相关推荐
阿黎梨梨2 小时前
跟 Git 打交道的正确姿势
前端
idcu2 小时前
深入 Lyt.js 路由系统:L6 生态系统层的核心
前端·typescript
idcu2 小时前
用 Lyt.js 构建 Todo 应用:完整教程
前端·typescript
七夜zippoe2 小时前
DolphinDB时间序列引擎:实时聚合计算
服务器·前端·时间序列·dolphindb·实时聚合
佳木逢钺2 小时前
pnpm 命令功能清单
前端
m0_738120722 小时前
渗透测试基础知识——从零认识JWT(JSON Web Token)身份令牌
服务器·前端·安全·web安全·网络安全·json
放下华子我只抽RuiKe52 小时前
React 从入门到生产(六):路由与导航
前端·人工智能·深度学习·react.js·前端框架·html·claude code
Sylus_sui2 小时前
实现:每行固定 5 个、自动换行、最后一行左对齐、数量不固定
前端·javascript·css
文滨2 小时前
10分钟搞定!Mac 配置 GitHub SSH 完全指南(小白也能看懂)
前端·macos·ssh·github