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>
相关推荐
天才熊猫君15 分钟前
配置与数据分离:一种可视化搭建的属性编辑方案
前端·javascript
林希_Rachel_傻希希24 分钟前
web性能之相关路径——AI总结
前端·javascript·面试
竹林81832 分钟前
用 wagmi v2 踩坑两天,我终于搞懂了多链钱包切换在 DeFi 前端中的正确姿势
前端·javascript
用户21366100357235 分钟前
Vue项目搜索功能与面包屑导航
前端·javascript
星栈39 分钟前
LiveView 的实时通信,爽是爽,但 PubSub 和广播也最容易把自己绕晕
前端·前端框架·elixir
用户29307509766940 分钟前
告别关键词匹配,拥抱向量语义 —— RAG 搜索从零到一
前端
独孤留白1 小时前
从C到Rust:告别 C 的"指针 + 长度"手动模式
前端·rust
掘金安东尼1 小时前
中小厂前端候选人简历面试拆解:从 HR 面、技术面到主管面的双赢提问法
前端·面试
天平10 小时前
油猴脚本创建webworker踩坑记录
前端·javascript·typescript