CSS常用属性设置
1.背景
- 设置元素的背景颜色
background-color: antiquewhite;
- 设置元素的背景图片,默认背景重复显示
background-image: url(../0.img/img-1.jpeg);
- 设置背景图片是否重复 no-repeat:不重复;repeat-x:横向重复;repeat-y:纵向重复;repeat:横向纵向重复(平铺)
background-repeat: repeat;
- 设置背景图片大小
background-size: 200px 200px;
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/43af5025520e2d2c5d9783ad88666ef1.png)
- 代码块
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>背景</title>
<style>
body {
background-color: antiquewhite;
background-image: url(../0.img/img-1.jpeg);
background-repeat: repeat;
background-size: 200px 200px;
}
</style>
</head>
<body>
</body>
</html>
2.文本
- color 文本颜色
color: blueviolet;
- 对齐方式 (左对齐是默认)
text-align: center;
- 文本修饰 text-decoration
设置上划线
text-decoration: overline;
设置下划线
text-decoration: underline;
设置中划线
text-decoration: line-through;
同时设置上中下划线
text-decoration: overline underline line-through;
- 去除文本修饰
text-decoration: none;
- 设置首行缩进 em:一个文字的高度
text-indent: 4em;
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/51d8662a11ee79e728dba340ca194ffd.png)
- 代码块
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>文本</title>
<style>
#div1 {
color: blueviolet;
}
#div2 {
text-align: center;
}
#div3 {
text-decoration: overline;
text-decoration: underline;
text-decoration: line-through;
}
#div4 {
text-decoration: overline underline line-through;
}
a {
text-decoration: none;
}
#p1 {
text-indent: 4em;
}
</style>
</head>
<body>
<div id="div1">文本1</div>
<div id="div2">文本2</div>
<div id="div3">文本3</div>
<p><div id="div4">文本4</div></p>
<a href="">超链接</a>
<p id="p1">这是一段文字,需要进行首行缩进</p>
</body>
</html>