background-clip: text 介绍和用法

本文介绍了background-clip属性,其在W3C标准中有border-box、padding-box、content-box三个值。重点讲解了background-clip: text,它是以文字范围裁剪背景图片,类似Photoshop的剪贴蒙版概念,且该属性仅Chrome兼容,兼容其他浏览器需用-webkit-background-clip: text。

前言背景

单词clip是 修剪 裁剪 的意思;
大家都知道: background-clip 属性规定背景的绘制区域。
在W3C标准的它有三个值: border-box | padding-box | content-box;
动字面上来理解 分别是 以盒边界来裁剪 | 以内边距为边界来裁剪 | 以内容区域来裁剪

如图:

 效果如下:

基本概念讲完: 我来回归到 background-clip: text;

从概念上来讲, clip就的值就是 规定 裁剪的范围..

background-clip: text; 顾名思义 就是 以文字的范围来裁剪背景图片.

这就也是 photoshop里的 剪贴蒙版 的概念-->(指定一个固定区域,区域的内容随意更换.)
不过 background-clip: text; 只兼容chrome,要想兼容其他浏览器就要用: -webkit-background-clip: text;

实例:
html

  <div class="clip">clip</div>

 css:

.clip {
  border: 1px solid red;
  font-size: 200px;
  font-weight: 900;
  width: 400px;
  height: 300px;
  background: url(https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1579425247124&di=7087c9b3781116f4440b0c9ec7722d9b&imgtype=0&src=http%3A%2F%2Ffile02.16sucai.com%2Fd%2Ffile%2F2014%2F0704%2Fe53c868ee9e8e7b28c424b56afe2066d.jpg) center center no-repeat;
  background-size: 100% 100%;

  -webkit-background-clip: text;
  color: transparent; 
}

效果如下:

转自:background-clip: text 介绍和用法 - 简书 

<template> <view class="container"> <view class="title"> <view class="headSpan">照明</view> <view class="lineSpan">行业智能供应链</view> </view> <view class="search-top search-normal"> <view class="search-box"> <input placeholder="请输入" type="text" v-model="searchText" /> </view> </view> <IndustryData></IndustryData> </view> </template> <script setup> import IndustryData from "@/components/IndustryData.vue" import { ref } from 'vue'; let searchText = ref('') </script> <style lang="scss"> @import "../../static/scss/publicContainer.scss"; $boxs-margin: 10px; //每个盒子之前的margin距离 .title { text-align: center; font-family: "PangMenZhengDao"; font-style: normal; display: flex; flex-direction: column; height: 50px; .headSpan { font-family: "PangMenZhengDao"; display: flex; width: 88px; height: 25px; flex-direction: column; justify-content: center; font-size: 22px; font-weight: 800; line-height: 22px; letter-spacing: 2.4px; background: linear-gradient(90deg, #E9BC82 12.5%, #FFEECB 51.09%, #E9BC82 89.67%); background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent; } .lineSpan { display: flex; width: 88px; height: 15px; flex-direction: column; justify-content: center; flex-shrink: 0; font-family: "PangMenZhengDao"; font-size: 10px; font-weight: 800; line-height: 12px; letter-spacing: 1px; background: linear-gradient(90deg, #E9BC82 12.5%, #FFEECB 51.09%, #E9BC82 89.67%); background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent; } } .search-top { position: sticky; top: calc(var(--status-bar-height) + $marginHead + $boxs-margin); } .search-normal { width: 65vw; } .search-box { display: flex; padding: 6px 12px; height: 28px; align-items: center; flex: 1 0 0; align-self: stretch; border-radius: 30px; background-color: #E6E6E6; color: black; z-index: 999; margin: $boxs-margin auto; } </style> 帮我修改代码,做到sticky触发的时候searchbox宽度为width: 65vw;,但是正常时候是100
06-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值