常用css选择器知识点巩固2015年1月26日
进入前端行业也有一段时间,总是觉得缺点儿什么。可能是之前没有经过系统化的学习吧(以前总是用到了什么才找什么),所以总是觉得自己的基础不够扎实。终于,决定,再次系统化的学习一下基础知识,巩固一下基础,我想每个大神都应该是这样过去的,我相信我也会成为一个优秀的前端开发者,只是我还需要一个过程。
努力一点,生活更美好……
如果这篇文章中有什么不对的地方,请一定给予指教,小弟感激不尽。同时,也希望这篇文章对和我一样的菜鸟,有一定的帮助。
代码运行效果:http://sandbox.runjs.cn/show/jl74m4es
1 <div class='ClassName'>类名选择器:"."+类名.eg:---.className{……}</div> 2 <div id="IDName">ID选择器:"#"+idName。eg:-------#IDName{……}</div> 3 <h1>元素选择器:元素(标签)名称.eg----------h1{……}</h1> 4 5 <h2>分组选择器:选择器名称+","+n选择器名称+{},eg:----h2, .group{……}</h2> 6 <div class="group">分组选择器:选择器名称+","+n选择器名称+{},eg:----h2, .group{……}</div> 7 8 <p class="">属性选择器:元素名称[+属性名称+]{},eg:---p[class]{},表示,所有p下,所有有class属性的样式</p> 9 <div class="p"> 10 <p class="">属性选择器:元素名称[+属性名称+]{},eg:---<strong>.p</strong>[class]{},表示,class='p'下面的元素中,有class属性的样式</p> 11 </div> 12 13 <input type="text" value="属性值选择器:元素名称['属性名'='属性值']{},eg:----input[type='text']{}"> 14 15 <ul class="parent"> 16 <li>后代选择器:选择器+"空格"+选择器{}。eg:----.parent li{}</li> 17 <li>例如本例子,父类ul的class='parent',再定义.parent li{},注意:本节点对所有的符合后代选择器的样式起作用。比如,小狗继承狗祖先的血统。因为小狗属于狗,符合狗的选择器</li> 18 </ul> 19 20 <ul class="parent01"> 21 <li>子代选择器:选择器+"空格>空格"+选择器{}。eg:----.parent01 > li{}</li> 22 <li>例如本例子,父类ul的class='parent',再定义.parent01 > li{}。注意:本节点只对符合选择器的子代选择的样式起作用,比如,狗妈妈只喂奶给自己的小狗,不喂养自己的孙子(狗没那寿命,尴尬),</li> 23 </ul> 24 25 <h1>这是h1标签</h1> 26 <h6 class="h6">相邻兄弟选择器:选择器 + 选择器{},eg:--------h1 + .h6{},表示,h1后面相邻的class为h6的样式</h6> 27 28 <a href="javascript:void(0)" class="a1">伪类选择器::link,未访问</a> 29 <a href="#" class="a2">伪类选择器::visited,访问过</a> 30 <a href="#" class="a3">伪类选择器::hover,指针停留在元素</a> 31 <a href="javascript:void(0)" class="a4">伪类选择器::active,激活状态</a> 32 33 <input type="text" class="input" value="伪类选择器::focus"> 34 35 <p class="p01">伪类选择器::before/:after.在目标元素前方,或者后方添加内容。eg:------.p01:before{}</p> 36 37 <ul class="parent03"> 38 <li>伪类选择器::first-child,第一个子类的样式.eg:-----.parent03 > li:first-child{}</li> 39 <li>这里是为li设置的同一样式</li> 40 <li>伪类选择器::last-child,最后一个子类的样式。.parent03 > li:last-child{}</li> 41 </ul> 42 43 <ul class="parent04"> 44 <li>css3伪类选择器::first-of-type,第一个子类的样式.eg:-----.parent03 > li:first-of-type{}</li> 45 <li>css3伪类选择器::nth-child(n),第n子类的样式.eg:-----.parent03 > li:nth-child(2){}</li> 46 <li>默认样式</li> 47 <li>css3伪类选择器::last-of-type,最后一个子类的样式.eg:-----.parent03 > li:last-of-type{}</li> 48 </ul>
1 *{margin:0;padding:0} 2 body{overflow-x:hidden;padding-bottom:50px} 3 .ClassName{margin-top:30px;height:50px;background-color:#454545;color:#fff;text-indent:50px;line-height:50px} 4 #IDName{margin-top:30px;height:50px;background-color:#f47920;text-indent:50px;line-height:50px} 5 h1{margin-top:30px;height:50px;background-color:#905a3d;text-indent:50px;line-height:50px} 6 h2,.group{margin-top:30px;height:50px;background-color:#8f4b2e;text-indent:50px;line-height:50px} 7 p[class],.p[class][alt]{margin-top:30px;height:50px;background-color:#5f3c23;text-indent:50px;line-height:50px} 8 input[type="text"]{margin-top:30px;width:100%;height:50px;border:0;background-color:#757522;text-indent:50px;font-size:30px} 9 .parent,.parent01{overflow:hidden;margin-top:30px;padding-bottom:15px;background-color:#80752c;list-style:none} 10 .parent li{margin-top:15px;margin-right:15px;margin-left:15px;height:100%;background-color:#454926;text-indent:35px;line-height:50px} 11 .parent01>li{margin-top:15px;margin-right:15px;margin-left:15px;height:100%;background-color:#b7ba6b;text-indent:35px;line-height:50px} 12 h1+.h6{margin-top:30px;height:50px;background-color:#2e3a1f;text-indent:50px;font-size:16px;line-height:50px} 13 a{display:block;margin-top:30px;height:50px;text-decoration:none;text-indent:50px;line-height:50px} 14 .a1:link{background-color:#5e005e;color:#fff} 15 .a2:link{background-color:#7b7b7b;color:#fff} 16 .a2:visited{background-color:#ea0000;color:#000} 17 .a3:link{background-color:#ff0080;color:#000} 18 .a3:hover{background-color:#921aff;color:#fff} 19 .a4:link{background-color:#ff0080;color:#000} 20 .a4:active{background-color:#921aff;color:#fff} 21 .input:focus{background-color:#be77ff} 22 .p01{height:50px;background-color:#9f35ff;text-indent:50px;line-height:50px} 23 .p01:before{background-color:#c1c1c1;content:'这里是css添加'} 24 .parent03,.parent04{overflow:hidden;margin-top:30px;padding-bottom:15px;background-color:#80752c;list-style:none} 25 .parent03>li,.parent04>li{margin-top:15px;margin-right:15px;margin-left:15px;height:100%;background-color:#b7ba6b;text-indent:35px;line-height:50px} 26 .parent03>li:first-child{background-color:#f0f} 27 .parent03>li:last-child{background-color:#be77ff} 28 .parent04>li:first-of-type{background-color:#adadad} 29 .parent04>li:last-of-type{background-color:#606060} 30 .parent04>li:nth-child(2){background-color:#b15bff}

浙公网安备 33010602011771号