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>
相关推荐
海兰30 分钟前
【web应用】Excel 项目数据自动化分析系统(AI 驱动分析)详细设计与部署指南(附源代码)
前端·人工智能·自动化·excel
2501_9400417433 分钟前
技术分享:高质量全栈开发提示词设计实践 —— 覆盖简单到复杂
前端·prompt
IT_陈寒1 小时前
Python的os.path.join居然能这么坑?
前端·人工智能·后端
艳阳天_.1 小时前
星瀚弹框页面实现
java·前端·python
EdgeOne边缘安全加速平台1 小时前
EdgeOne Web 防护×AI 升级:让 AI 既参与攻击识别,也参与误报纠错
前端·人工智能·腾讯云·edgeone
nuIl1 小时前
实现一个 Coding Agent(6):并行工具调用
前端·ai编程·cursor
Rain5092 小时前
2.1 Nest.js 项目初始化与模块化架构
开发语言·前端·javascript·后端·架构·数据分析·node.js
cjp5602 小时前
009. ASP.NET WEB API 用户关联esp32设备
前端·后端·asp.net
Insseals2 小时前
因斯特浮动模块快速接头✨五大核心优势
前端
沐土Arvin2 小时前
港澳台行政区域json
前端