批改状态:合格
老师批语:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>常用选择器</title>
</head>
<style>
/*标签选择器:根据标签名称来选择页面元素*/
ul{
margin: 0;
padding: 10px 5px;
width: 520px;
border:1px dashed #666;
padding: 10px 5px;
}
/*子块撑开父级区域*/
ul:after{
content: '';
display: block;
clear: both;
}
ul li{
list-style: none;
float: left;
width: 40px;
height: 40px;
line-height: 40px;
text-align: center;
border-radius: 50%;
box-shadow: 2px 2px 2px #888;
background-color: skyblue;
margin:5px;
}
/*id选择器*/
#item1{
background-color: coral;
}
/*类选择器/class选择器*/
.item2{
background-color: gold;
}
/*属性选择器:属性名*/
ul li[class] {
background-color: blueviolet;
}
/*属性选择器:以指定属性值开头的元素*/
ul li[class^="cat"] {
background-color: brown;
}
/*属性选择器:以指定属性值结尾的元素*/
ul li[class$="png"] {
background-color: red;
}
/*属性选择器:属性值中包含指定的子串*/
ul li[class*="nav"] {
background-color: green;
}
/*后代选择器,层级选择器*/
body ul li{
border:1px solid black;
}
/*子选择器*/
ul > li[class$="pig"]{
background-color: greenyellow;
}
/*相邻选择器*/
ul li[class$="png"]~*{
background-color: black;
color: white;
}
/*相邻兄弟选择器*/
ul li[class$="png"] + li {
background-color: pink;
color: black;
}
/*群组选择器*/
h1,p {
font-size: 2rem;
font-weight: lighter;
margin: 0;
}
/*伪类选择器:链接*/
a {
font-size: 2rem;
}
/*访问前*/
a:link {
color: red;
}
/*访问过后*/
a:visited {
color: orange;
}
/*获取焦点的时候*/
a:focus {
color:purple;
}
/*鼠标悬停的时候*/
a:hover {
color:green;
}
/*鼠标点击激活的时候*/
a:active {
color: blue;
}
/*伪类选择器:位置*/
/*第一个*/
ul li:first-child {
background-color: #efefef!important;
}
/*最后一个*/
ul li:last-child {
background-color: red;
}
/*指定的行*/
ul li:nth-child(7) {
background-color: pink;
}
/*根据指定的奇数或偶数行来定位*/
ul li:nth-child(even) {
/*偶数:even;奇数:odd*/
/*background-color: purple!important;*/
}
/*伪类选择器:根据子元素的数量*/
/* ol:only-child {
background-color: lawngreen;
}*/
ol li:only-child {
background-color: lawngreen;
}
/*倒数选择*/
ul li:nth-last-child(3){
background-color: wheat;
}
/*同时选择多个*/
ol li:nth-of-type(2){
background-color: wheat;
}
:empty{
width: 360px;
height: 290px;
background-color: wheat;
}
:empty:after{
content: '看到我了吗?';
}
:empty:before{
content: url("../04/images/dog.jpg");
}
</style>
<body>
<ul>
<li id="item1">1</li>
<li class="item2">2</li>
<li class="cat dog pig">3</li>
<li class="dog png">4</li>
<li class="nav1">5</li>
<li class="nav2">6</li>
<li class="pig">7</li>
<li>8</li>
<li>9</li>
<li>10</li>
</ul>
<h1>CSS选择器大法</h1>
<p>css选择器非常重要,特别是对于学习js,jquery以及其他前端框架</p>
<a href="http://www.php.cn">PHP中文网</a>
<ol>
<li>列表项1</li>
</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>点击 "运行实例" 按钮查看在线实例
截图:

手抄代码:

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号