博主信息
博文 46
粉丝 3
评论 2
访问量 47067
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
css选择器 2018年3月21日
墨雨的博客
原创
875人浏览过

CSS基本选择器联系代码:


实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>3月21日作业 CSS基本选择器练习</title>
	<style type="text/css">
		ul {   
			margin: 0;
			width: 250px;
			padding: 10px 5px;
		}

		ul:after {  
			content:'';  
			display: block; 
			clear:both;   
		}
		
		li { 
			list-style: none; 
			float: left;  
			width: 20px;  
			height: 20px; 
			line-height: 20px; 
			text-align: center; 
			border-radius: 50%; 
			background: skyblue; 
			margin-right: 5px; 
		}
		#item1 {
			background-color: red;
		}

		.red {
			background-color: red;
		}
		
	</style>
</head>
<body>
<table border="1" cellspacing="0" cellpadding="5" align="center" width="900">
	<caption><h3>基本选择器</h3></caption>
	<tr>
		<th>选择器</th>
		<th>代码举例</th>
		<th>功能描述</th>
		<th>实例演示</th>
	</tr>
	<tr>
		<td>元素选择器</td>
		<td>ul{}</td>
		<td>选择指定类型的html元素</td>
		<td>
			<ul>
				<li>1</li>
				<li>2</li>
				<li>3</li>
				<li>4</li>
			</ul>
		</td>
	</tr>
	<tr>
		<td>id选择器</td>
		<td>#id{}</td>
		<td>选择指定id属性值的任意类型的html元素</td>
		<td>
			<ul>
				<li >1</li>
				<li id="item1">2</li>
				<li>3</li>
				<li>4</li>
			</ul>
		</td>
	</tr>
	<tr>
		<td>类择器</td>
		<td>.class{}</td>
		<td>选择指定class属性值的的任意类型的任意多个元素</td>
		<td>
			<ul>
				<li >1</li>
				<li >2</li>
				<li class="red">3</li>
				<li>4</li>
			</ul>
		</td>
	</tr>
</table>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

CSS层次选择器联系代码:


实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>3月21日作业 CSS层次选择器练习</title>
	<style type="text/css">
		ul {   
			padding: 0;
			margin: 0;
			width: 250px;
			/*border: 0px dashed #666;*/
			padding: 10px 5px;
		}

		ul:after {  
			content:'';  
			display: block; 
			clear:both;   
		}
		
		li { 
			list-style: none; 
			float: left;  
			width: 20px;  
			height: 20px; 
			line-height: 20px; 
			text-align: center; 
			border-radius: 50%; 
			background: skyblue; 
			margin-right: 5px; 
		}
				
/*		ul li {  
		   color: black;
	    }*/

/*        ul> li {  
			background-color: red;

		}
*/
		#item2 + li {
			background-color: black; 
		}
		
		#item2 ~ li {
			background-color: black; 
		}

	</style>
</head>

<table border="1" cellspacing="0" cellpadding="5" align="center" width="900">
	<caption><h3>层次选择器</h3></caption>
	<tr>
		<th>选择器</th>
		<th>代码举例</th>
		<th>功能描述</th>
		<th>实例演示</th>
	</tr>
	<tr>
		<td>父子选择器</td>
		<td>ul li{}</td>	
		<td>选择包含在共同父级下的指定元素</td>
		<td>
			<ul>
				<li>1</li>
				<li>2</li>
				<li>3</li>
				<li>4</li>
			</ul>
		</td >
	</tr>	
	<tr>
		<td>子元素选择器</td>
		<td>ul>li{}</td>	
		<td>选择父元素下指定子元素</td>
		<td>
			<ul>
				<li>1</li>
				<li>2</li>
				<li>3</li>
				<li>4</li>
			</ul>
		</td>
	</tr>
	<tr>
		<td>相邻兄弟选择器</td>
		<td>#item2+li{}</td>	
		<td>选择指定元素后面的第一个元素</td>
		<td>
			<ul>
				<li id="item2">1</li>
				<li>2</li>
				<li>3</li>
				<li>4</li>
			</ul>
		</td>
	</tr>
	<tr>
		<td>全部兄弟选择器</td>
		<td>#item2~li{}</td>	
		<td>选择指定元素后面的所有元素</td>
		<td>
			<ul>
				<li>1</li>
				<li>2</li>
				<li>3</li>
				<li id="item2">4</li>
				<li>5</li>
				<li>6</li>
				<li>7</li>
				<li>8</li>
				
			</ul>
		</td>
	</tr>
</table>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

CSS属性选择器联系代码:


实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>3月21日作业 CSS属性选择器练习</title>
	<style type="text/css">
		ul {   
			padding: 0;
			margin: 0;
			width: 250px;
			/*border: 0px dashed #666;*/
			padding: 10px 5px;
		}

		ul:after {  
			content:'';  
			display: block; 
			clear:both;   
		}
		
		li { 
			list-style: none; 
			float: left;  
			width: 20px;  
			height: 20px; 
			line-height: 20px; 
			text-align: center; 
			border-radius: 50%; 
			background: skyblue; 
			margin-right: 5px; 
		}
		
		*[id] {  
			background-color: red;
		}

		li[class="grn"] {
			background-color: red;
		}

		li[class ~= "my"] {
			background-color: red;
		}
		
	
		li[class ^= "ma"] {
			background-color: red;
		}

		li[class $= "123"] {
			background-color: red; 
		}

		li[class *= "8"] {
			background-color: red;  

	


	</style>
</head>
<body>
<table border="1" cellspacing="0" cellpadding="5" align="center" width="900">
	<caption><h3>属性选择器</h3></caption>
	<tr>
		<th>选择器</th>
		<th>代码举例</th>
		<th>功能描述</th>
		<th>实例演示</th>
	</tr>
	<tr>
		<td>属性选择器</td>
		<td>li[class]{}</td>	
		<td>选择所有带有指定属性的元素</td>
		<td>
	<ul>
		<li>1</li>
		<li id="item1">2</li>
		<li>3</li>
		<li>4</li>
	</ul>
	</td>

	</tr>
	<tr>
		<td>属性选择器</td>
		<td>li[class="值"]{}</td>	
		<td>选择所有指定属性等于指定值的元素</td>
		<td>
	<ul>
		<li>1</li>
		<li >2</li>
		<li class="grn">3</li>
		<li>4</li>
	</ul>
	</td>

	</tr>
		
	<tr>
		<td>属性选择器</td>
		<td>li[class~="值"]{}</td>	
		<td>选择所有指定属性值中包含指定单词的元素</td>
		<td>
	<ul>
		<li>1</li>
		<li class="css my ww">2</li>
		<li>3</li>
		<li>4</li>
	</ul>
	</td>

	</tr>
	<tr>
		<td>属性选择器</td>
		<td>li[class^="值"]{}</td>	
		<td>选择所有以指定属性值开头的元素</td>
		<td>
	<ul>
		<li>1</li>
		<li>2</li>
		<li>3</li>
		<li class="maddddd">4</li>
	</ul>
	</td>

	</tr>
		<tr>
		<td>属性选择器</td>
		<td>li[class$="值"]{}</td>	
		<td>选择所有以指定属性值结尾的元素</td>
		<td>
	<ul>
		<li class="wowo123">1</li>
		<li>2</li>
		<li>3</li>
		<li>4</li>

	</ul>
	</td>

	</tr>
		<tr>
		<td>属性选择器</td>
		<td>li[class*="值"]{}</td>	
		<td>选择所有指定属性值中包含指定值的元素</td>
		<td>
	<ul>
		<li>1</li>
		<li class="2324870">2</li>
		<li>3</li>
		<li>4</li>
	</ul>
 </td>
	</tr>
</table>
</body>
</html>

运行实例 »

点击 "运行实例" 按钮查看在线实例

手抄作业:

IMG_20180322_190034.jpgIMG_20180322_190046.jpgIMG_20180322_190049.jpg

批改状态:合格

老师批语:这两天的作业已检查! 完成的很不错!!继续加油!!!
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系admin@php.cn举报处理!
全部评论 文明上网理性发言,请遵守新闻评论服务协议
0条评论
作者最新博文
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

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

  • 登录PHP中文网,和优秀的人一起学习!
    全站2000+教程免费学