gpt4 book ai didi

css - 从背景中剪下的透明文本

转载 作者:行者123 更新时间:2023-11-27 23:34:01 28 4
gpt4 key购买 nike

有什么方法可以使用 CSS 制作出如下图所示的透明文本从背景中切出效果吗?
由于图像替换文本而失去所有宝贵的 SEO 将是可悲的。

Transparent text cut out of background

我首先想到的是阴影,但我想不通......

图片为网站背景,绝对定位<img>标记

最佳答案

css3 可以,但不是所有浏览器都支持

带背景剪辑:文本;您可以为文本使用背景,但必须将其与页面背景对齐

body {
background: url(http://www.color-hex.com/palettes/26323.png) repeat;
margin:10px;
}
h1 {
background-color:#fff;
overflow:hidden;
display:inline-block;
padding:10px;
font-weight:bold;
font-family:arial;
color:transparent;
font-size:200px;
}
span {
background: url(http://www.color-hex.com/palettes/26323.png) -20px -20px repeat;
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
display:block;
}
<h1><span>ABCDEFGHIKJ</span></h1>

http://jsfiddle.net/JGPuZ/1337/


自动对齐

用一点javascript你可以自动对齐背景:

$(document).ready(function(){
//Position of the header in the webpage
var position = $("h1").position();
var padding = 10; //Padding set to the header
var left = position.left + padding;
var top = position.top + padding;
$("h1").find("span").css("background-position","-"+left+"px -"+top+"px");
});
body {
background: url(http://www.color-hex.com/palettes/26323.png) repeat;
margin:10px;
}
h1 {
background-color:#fff;
overflow:hidden;
display:inline-block;
padding:10px;
font-weight:bold;
font-family:arial;
color:transparent;
font-size:200px;
}
span {
background: url(http://www.color-hex.com/palettes/26323.png) -20px -20px repeat;
-webkit-text-fill-color: transparent;
-webkit-background-clip: text;
display:block;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<h1><span>ABCDEFGHIKJ</span></h1>

http://jsfiddle.net/JGPuZ/1336/

关于css - 从背景中剪下的透明文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57337272/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com