批改状态:未批改
老师批语:
熟练使用css进行网页美化,能给页面带来丰富的内容和色彩
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>常用选择器与优先级(seceltor)</title>
<style>
/*标签选择器*/
h3 {
background-color:lightgreen;
color:red;
}
/*class选择器*/
.bg-blue{
background-color: skyblue;
}
/*id选择器*/
#bg-yellow{
background-color: yellow;
}
</style>
</head>
<body>
<h3 class="bg-blue">样式规则 = 选择器 + 样式声明</h3>
<h3 class="bg-blue" id="bg-yellow" style="background-color:pink">样式规则 = 选择器 + 样式声明</h3>
<!--选择器优先级顺序 标签 < class < id-->
<!--用js实现更改h3标签背景色-->
<script type="text/javascript">
document.getElementById('bg-yellow').style.backgroundColor = 'lightgrey';
</script>
</body>
</html>点击 "运行实例" 按钮查看在线实例
以上代码涉及知识点总结:
一.常用css选择器有标签选择器、类class选择器、id选择器,类选择器用 . 引用,id选择器用 # 引用
二.优先级顺序是 标签 < class < id
三.比id选择器更高级的可以用js,如document.getElementById('id选择器名字').style.backgroundColor='颜色',更改id属性的元素的背景色。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号