本文摘自PHP中文网,作者V,侵删。
什么是选择器?
选择器的作用是通过它可以找到元素,把css样式传递给元素!css选择器主要分为:基本选择器、属性选择器、组合选择器与伪类选择器四个大类!
css基本选择器
基本选择器又分为:*通配符、标签选择器、class选择器、id选择器,在这里需要注意的编程思想在css层叠样式表中元素有且仅有一个id。注意以下几点1.id唯一性2.元素id不相同,就像每一个人只有一个身份证一样,ID就代表身份证3.class选择器不具有唯一性,它可以重复使用!此外这个*通配符代表的是全局。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <!DOCTYPE html>
<html>
<head>
<meta charset= "UTF-8" >
<meta name= "viewport" content= "width=device-width, initial-scale=1.0" >
<title>css基本选择器</title>
<style type= "text/css" >
*{
color : skyblue;
}
div{
color : red ;
}
.box{
color : steelblue;
} .box{ color : steelblue;}也可以写成*.box{ color : steelblue;}代表的所有的box字体颜色为 steelblue
#content{
color : tomato;
}
</style>
</head>
<body>
<div id= "content" >
大灰牛博客专注web前端技术学习
</div>
</body>
</html>
|
(推荐教程:CSS入门教程)
css组合选择器
把基本选择器通过特殊符号串在一起有意见称之为css组合选择器,常见的css组合选择器有:分组选择器、嵌套选择器、子选择器、相邻同级别选择器
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | <!DOCTYPE html>
<html>
<head>
<meta charset= "UTF-8" >
<meta name= "viewport" content= "width=device-width, initial-scale=1.0" >
<title>css组合选择器</title>
<style type= "text/css" >
div{
font-size : 24px ;
}
div,p{
color : teal ;
}
div p{
color : red ;
}
ul>li{
font-size : 24px ;
list-style : square ;
}
div+p{
color : blue ;
}
</style>
</head>
<body>
<div>
成功的花,人们只惊羡她现时的明艳!然而当初她的芽儿,浸透了奋斗的泪泉,洒遍了牺牲的血雨
<p>自以为懂得很多了经历很多了最后才知道都是那么的可笑</p>
</div>
<p>我们不要只看成功者荣誉的瞬间,更要看到成功者为之努力、为之奋斗的过程,从而激励自己也不断付出,奔着那个成功的目标前进.</p>
<p>成功的花,人们只惊羡她现时的明艳!然而当初她的芽儿,浸透了奋斗的泪泉,洒遍了牺牲的血雨<span>我们不要只看成功者荣誉的瞬间,更要看到成功者为之努力、为之奋斗的过程,从而激励自己也不断付出,奔着那个成功的目标前进.</span></p>
<ul>
<li> 1 </li>
<li> 2 </li>
<li> 3 </li>
</ul>
</body>
</html>
|
css属性选择器
基本选择器[属性]、基本选择器[属性=值]、 基本选择器[属性~=值]空格符隔开多个、 基本选择器[属性^=值]以什么开始、 基本选择器[属性$=值]以什么结束
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | <!DOCTYPE html>
<html>
<head>
<meta charset= "UTF-8" >
<meta name= "viewport" content= "width=device-width, initial-scale=1.0" >
<title>css属性选择器</title>
<style type= "text/css" >
div[title]
div[title=english]{
color : blue ;
}
div[title~=en]{
color : #f90 ;
font-weight : bold ;
}
p,div[title^=zh]{
font-size : 24px ;
color : brown;
}
div[title$=china]{
letter-spacing : 10px ;
text-decoration : line-through ;
font-style : italic ;
}
</style>
</head>
<body>
<div title= "english" >
If you can NOT explain it simply, you do NOT understand it well enough
</div>
<div title= "english en yingyu" >
你们没发现嘛? 2013 爱你一生, 2014 爱你一世, 2015 爱你一屋, 2016 爱你一路, 2017 爱你一切。
|
相关视频教程推荐:css视频教程
以上就是关于css选择器的详细介绍的详细内容,更多文章请关注木庄网络博客!
相关阅读 >>
css column-rule-style属性怎么用
css代码如何居中
css line-height属性怎么用
使用css flexbox构建网站标题
css中主要有哪三种选择符
css transition-delay属性怎么用
css实现等高布局的三种方式(代码示例)
css怎么设置浮动
css怎么去掉div边框
css怎么控制不换行
更多相关阅读请进入《css》频道 >>
人民邮电出版社
本书对 Vue.js 3 技术细节的分析非常可靠,对于需要深入理解 Vue.js 3 的用户会有很大的帮助。——尤雨溪,Vue.js作者
转载请注明出处:木庄网络博客 » 关于css选择器的详细介绍