<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>css选择器</title>
<style>
/*
标签选择器(element元素)
标签名{
样式属性名称1:值1;
}
*/
/* div{
font-size:20px;
color:skyblue;
} */
/*
类选择器
在标签中指定class属性,
.class{
样式属性名称1:值1;
...
}
*/
/* .ch{
font-size: 30px;
color: bisque;
} */
/*
优先级:类选择器>标签选择器
*/
/*
id选择器
在html标签中指定id属性="id属性值"
css样式代码
#id{
样式属性名称1:值1;
...
}
注意事项:一个html页面中不能出现同名id属性值(必须唯一)
javascript:dom编程(基于文档对象模型编程):获取标签对象
document.getElementById("id属性值")
document.getElementsByClassName("class属性值")
*/
/* #s{
font-size: 60px;
color: crimson;
} */
/*优先级:id选择器>class选择器>标签选择器*/
/*
并集选择器
写法
selector1,select2{
样式属性名称1:值1;
...
}
*/
/* #s,.ch{
font-size: 60px;
color: blue;
} */
/*
交集选择器:前面标签所在的子元素(子元素选择器)
selector1 selector2...{
样式属性名称1:值1;
}
*/
/* #s span{
font-size: 35px;
color: aquamarine;
} */
/*
通用选择器*(表示所有)
*{
样式代码
}
*/
*{
font-size: 20px;
color: chocolate;
font-family: 楷体;
}
</style>
</head>
<body>
<div class="ch" id="s"><span>span标签</span></div>
<div class="ch">div2</div>
<div>div3</div>
<span>span标签</span>
</body>
</html>
CSS选择器
于 2022-08-26 14:15:04 首次发布