1.CSS的语法格式
selector { property : value ; …}
selector叫做选择器,它决定了后面大括号内的样式对哪些元素生效
property : value 叫做一条CSS样式
每条样式都能够改变selector选中元素的展现
property成为样式名,value是对应的样式值
CSS样式可以有很多条,它们包裹在大括号内部,每条样式之间通过 分号 ;分割
CSS的样式对大小写不敏感,我们推荐统一使用小写
具有 相同样式 的选择器,可以分成一个组,之间用逗号分隔
例如
.box1,box2,box3{
height: 100px;
background: yellow;
}
小例子:
h1{
color: red;
font-size: 30px;
}
/* # 井号 对应 id 选择器
font-weight: bold; 控制字体的粗细 加粗
text-indent: 2em; 控制文案的缩进 两个文字的缩进距离
*/
#text{
font-weight: bold;
text-indent: 2em;
}
.box1,box2,box3{
height: 100px;
background: yellow;
}
练习例子:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>css的语法</title>
<style>
h1,h2 {
color: red;
/* 居中 */
text-align: center;
/* 阴影 */
text-shadow: 5px 5px 5px blue;
}
</style>
</head>
<body>
<h1>华为智慧屏电视</h1>
<h2>华为路由器</h2>
</body>
</html>
笔记:
CSS基本语法-笔记
一个基本结构,三个注意事项
- 选择器 { 样式名: 样式值 ;}
1.分号分隔
2.小写 推荐习惯
3.逗号分隔