css常用选择器

来源:互联网 发布:北京凶宅数据库查询 编辑:程序博客网 时间:2024/06/15 15:18
基本选择器:(优先级:id选择器>class选择器>元素选择器)
1)元素选择器
格式:html标签名{css属性}
例:<style type = "text/css">
span{coloe:red;font-size:100px}
</style>
2)id选择器
例:<div id="div1">hello</div>
<div id="div2">hello</div>

<style type = "text/css">
#div1{background-color:red}
#div2{background-color:yellow}
</style>
3)class选择器
语法:.class的值{css属性}
例:<div class="style1">hello</div>
<div class="style2">hello</div>

<style type = "text/css">
.style1{background-color:red}
.style2{background-color:yellow}
</style>
属性选择器
语法:元素选择器[属性="属性值"]{css属性}
伪元素选择器
a标签的伪元素选择器
语法:
静止:a:link{css属性}
悬浮:a:hover{css属性}
触发:a:active{css属性}
完成状态:a:visited{css属性}
层级选择器
语法:从外层到里层依次书写,用空格分开
原创粉丝点击