批改状态:合格
老师批语:
今天学习的多种的选择器及CSS三种单位
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
/*标签选择器*/
ul li{float: left;
width: 60px;
height: 60px;/*使宽高相同才能变成圆形*/
line-height: 60px;
text-align: center;
list-style: none;
background: #2D75C1;
border-radius: 50%;/*设置边框圆角*/
margin-right: 5px;
box-shadow: 4px 4px 4px/*阴影*/
}
/*伪类选择器*/
li:hover{background: #160CEB!important}/*!imprtant为重要,忽略优先级*/
/*id选择器(#)*/
#one{background: #BF3436}
/*class选择器*/
.two{background: #0EAA3D}
/*属性选择器:属性名*/
ul li[class]{background: #ccc}
/*属性选择器:属性值*/
ul li[id="three"]{background: #498E11}
/*属性选择器:以指定属性属性值开头*/
ul li[class^="cat"]{background: #3B0405}
/*属性选择器:以指定属性属性值结尾*/
ul li[class$="pig"]{background: #C129A9}
/*属性选择器:属性值包含指定字符串*/
ul li[class*="dog"]{background: #14A266}
/*后代选择器*/
body ul li{border: 1px solid skyblue}
/*子选择器*/
ul > li[class^="pig"]{background: #481CB3}
/*相邻选择器*/
ul li[class$="dog"] ~ * {background: #B1BFAE}/*不包括当前元素*/
/*相邻兄弟选择器*/
ul li[class="seven"] + li{background: #CF34C4}
/*群组选择器(用逗号分隔)*/
h1 , a{background: #ccc; font-size: 2em}
/*伪类选择器:链接*/
a {color: black;background: white}
/*访问前*/
a:link{color: antiquewhite}
/*访问后*/
a:visited{color: aqua}
/*用Tab获取焦点时*/
a:focus{color: aquamarine}
/*s鼠标悬停时*/
a:hover{color: black}
/*鼠标点击的一刹那时*/
a:active{color: yellow}
/*伪类选择器:位置*/
/*选择集合中的第一个元素*/
ul li:first-child{background: #D1DF3F!important}
/*选择集合中最后一个元素*/
ul li:last-child{background: #4F0B0C}
/*按索引选择指定的元素(注意从1开始,不是0)*/
ul li:nth-child(6){background: #AF090C}
ul li:nth-last-child(4){background: #91ADE7}
/*选择所有的偶数于奇数元素(2n偶数,2n+1奇数。even偶数,odd奇数)*/
ul li:nth-child(odd){background: #8C1315}
/*伪类选择器:根据元素数量*/
/*选择具有唯一子元素的元素*/
ol :only-child{background: #9A2527}
/*选择指定类型的唯一子元素*/
ol li:only-of-type{background: #AC1F22}
/*选择指定父级的第二个<li>元素*/
ol li:nth-of-type(2){background: #463CC0}
/*选择页面中为空的元素*/
:empty{width: 100px;
height: 100px;
background: #ccc}
:empty:after{content: '111';}
:empty:before{content: url(../../8.13(day2)/1.png);}
</style>
</head>
<body>
<ul>
<li id="one">1</li>
<li class="two">2</li>
<li id="three">3</li>
<li class="cat dog pig">4</li>
<li class="pig dog dog">5</li>
<li class="cat dog pig">6</li>
<li class="seven">7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
<h1 style="clear: both">这节课讲的是各种各样的选择器</h1>
<a href="www.baidu.com" target="_blank">很多,很重要</a>
<ol>
<li>列表项1</li>
<!--
现在给ol再添加一个子元素<p>,有二个子元素了,所以子元素不再唯一,
如何才能选中唯一的li元素呢?only-of-type
-->
<p>我是一个段落</p>
</ol>
<ol>
<li>列表项1</li>
<li>列表项2</li>
<li>列表项3</li>
</ol>
<ol>
<li>列表项1</li>
<li>列表项2</li>
<li>列表项3</li>
<li>列表项4</li>
</ol>
<div></div>
</body>
</html>点击 "运行实例" 按钮查看在线实例
CSS中的三种单位:

个人总结:
老师讲了很多种选择器,刚开始我的脑子是懵的。后来,自己把作业做下来之后,就对这些选择器有了一个比较清楚的认识。正所谓,万变不离其宗,找对位置就可以了。
真的充实!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号