好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

css怎么给文字加背景

方法:1、用“color: transparent”设置文字透明;2、用“background -i mage:url("图片地址")”给文字加背景图片;3、用“background-clip: text;”将图片和文字融合,实现文字背景效果。

本教程操作环境:windows7系统、CSS3 && HT ML 5版、Dell G3 电 脑。

今天我们我们来看看使用CSS怎么给文本添加背景图,让文字变得生动好看!在我们想要创建一个 较大 的文本标题,但 不想 使用普通又枯燥的颜色来修饰时,非常有用!
我们先来看看效果图:

下面我们来研究一下是怎么实现这个效果的:

1、首先是HTML部分,定义两个标题

<body>
	< h1 >拼多多 培训 </h1>
	<h3>拼多多培训</h3>
</body>

2、然后 开始 定义 css 样式来进行修饰:

body {
  dis play : flex;
  align- IT ems:  center ;
  justify-content: center;
  flex-direction: column;
  width: 100%;
  text-align: center;
  min-h ei ght: 100vh;
  font- Size:  100px;
  font-f ami ly:Arial, Helvetica, sans -s erif;
}

3、最后就是给文字添加背景图片:

将文字原本的颜色设置为 transparent 透明,然后 利用 background-image 属性给文字加背景图片

h1 {
    color: transparent;
    background-image: url("001. jpg ");
}

h3{
    color: transparent;
    background-image: url("002");
}

发现效果是这样的,不如人意。这是因为缺少了一个关键属性 background-clip 。 background-clip 属性是一个 CSS3 新属性 ,要添加前缀来兼容其他浏览器

h1 {
    color: transparent;
    background-image: url("001.jpg");
	background-clip: text;
    - webkit -background-clip: text;
}

h3{
    color: transparent;
    background-image: url("002.jpg");
	background-clip: text;
    -webkit-background-clip: text;
}

ok,大功告成!下面附上完整代码:

<html>
<head>
< ;m eta charset="utf-8">
<title></title>
<style ty PE ="text/css">
body {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  width: 100%;
  text-align: center;
  min-height: 100vh;
  font-size: 100px;
  font-f am ily:Arial, Helvetica, sans-serif;
}
h1 {
    color: transparent;
    background-image: url("001.jpg");
	background-clip: text;
    -webkit-background-clip: text;
}

h3{
    color: transparent;
    background-image: url("002.jpg");
	background-clip: text;
    -webkit-background-clip: text;
}
</style>
</head>
<body>
	<h1>拼多多培训</h1>
	<h3>拼多多培训</h3>
</body>
</html>

推荐学习:CSS视频教程

以上就是css怎么给文字加背景的详细内容,更多请关注其它相关 文章 !

总结

以上是 为你收集整理的 css怎么给文字加背景 全部内容,希望文章能够帮你解决 css怎么给文字加背景 所遇到的问题。

如果觉得 网站内容还不错, 推荐好友。

查看更多关于css怎么给文字加背景的详细内容...

  阅读:45次