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>
相关推荐
梦de天空一米168842 分钟前
【一个重复id让游戏卡在62%,聊聊配置表检查】
前端
用户34346127832044 分钟前
用户认证系统在高并发下的幂等性与限流策略踩坑实录
css
ryn483981 小时前
01 一个功能模块,怎么分层才不乱
前端·ai编程·claude
Amos_Web1 小时前
通过 Rspack 源码学 Rust(五):读懂 Result 与问号运算符的错误返回
前端
杨航 AI1 小时前
JEV的用法
java·前端·数据库
Amos_Web1 小时前
Rspack 源码解析(三十五):rspack_error 如何用 miette 渲染带源码定位的错误链
前端
去伪存真1 小时前
高敏资产场景下的大模型协同设计架构
前端·agent
修炼的dance1 小时前
OCR预处理测了108组,纠斜去噪有用,坑在顺序和力度
前端
疯华整猫1 小时前
Android 16 后台常驻适配:用 Trae 搭一套“前台服务 + 加急 Job”的可存活架构
前端
不可能片场1 小时前
AI视频成片 帧间差分把拼接缝照出来
前端·electron