博主信息
博文 44
粉丝 0
评论 1
访问量 37828
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
3月21日作业
时光记忆的博客
原创
742人浏览过

1.基本选择器

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>1.基本选择器</title>

	<!-- 标签、id、class选择器 -->
	<style type="text/css">
		ul{
			padding: 0;
			margin:0;
			width:450;
			border:1px dashed #666;
			padding:10px 5px;
		}

		ul:after{
			content:'';
			display: block;
			clear:both;
		}

		li{
			list-style: none;
			float:left;
			width:40px;
			line-height: 40px;
			text-align: center;
			border-radius:50%;
			background-color: skyblue;
			margin-right:5px;
		}
/*id选择器*/
		#item1{
			background-color: lightgreen;
		}
		/*类选择器*/
		.green{
			background-color: lightgreen;
		}
		/*父子选择器*/
		ul li{
			color: white;
		}
		/*通配选择器*/
		ul *{
			border: 1px solid black;
		/*子元素选择器*/
		ul > li {
			background-color: :blue;
		}
		/*相邻兄弟选择器*/
		#item2 + li {
			background-color: black;
		}
		/*选择全部兄弟*/
		#item2 ~ li {
			background-color: black;
		}
	</style>
		}
</head>
<body>
	<ul>
		<li id="item1">1</li>
		<li class="green">2</li>
		<li class="green">3</li>
		<li>4</li>
		<li>5</li>
		<li id="item2">6</li>
		<li>7</li>
		<li>8</li>
		<li>9</li>
	</ul>	
</body>
</html>

运行实例 »

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

2.属性选择器

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>4.属性选择器</title>

	<!-- 标签、id、class选择器 -->
	<style type="text/css">
		ul{
			padding: 0;
			margin:0;
			width:450;
			border:1px dashed #666;
			padding:10px 5px;
		}

		ul:after{
			content:'';
			display: block;
			clear:both;
		}

		li{
			list-style: none;
			float:left;
			width:40px;
			line-height: 40px;
			text-align: center;
			border-radius:50%;
			background-color: skyblue;
			margin-right:5px;
		}
/*id选择器*/
		 #item1{
			/*background-color: lightgreen;*/
		}
		类选择器
		.green{
			/*background-color: lightgreen;*/
		}
		父子选择器
		ul li{
			/*color: white;*/
		}
		通配选择器
		ul *{
			/*border: 1px solid black;*/
		子元素选择器
		ul > li {
			/*background-color: :blue;*/
		}
		相邻兄弟选择器
		#item2 + li {
			/*background-color: black;*/
		}
		选择全部兄弟
		#item2 ~ li {
			/*background-color: black;*/
		} 

		/*根据属性名来选择元素
		/*选中所有有ID属性的元素*/
		*[id] {
			/*background-color: red;*/
		}

		/*根据属性的名各值来选元素*/
		li[class="green"]{
			/*background-color: lightgreen;*/
		}

		/*选择class属性中实习实习包括指定单词的元素*/
		li[class ~= "red"]{
			/*background-color: brown;*/
		}
		/*选择以‘ph'开头的顺样式的元素*/
		li[class ^= "ph"]{
			/*background-color: coral;*/
		}

		/*选择以's'结尾的类样式的元素*/
		li[class $= "s"]{
			/*background-color: lime;*/
		}

		/*选择属性值中包括指定字母'e'的元素*/
		li[class *= "e"]{
			background-color: yellowgreen;
		}

	</style>
</head>
<body>
	<ul>
		<li id="item1">1</li>
		<li class="green">2</li>
		<li class="green">3</li>
		<li class="red">4</li>
		<li>5</li>
		<li id="item2">6</li>
		<li class="php">7</li>
		<li class="phpcss">8</li>
		<li>9</li>
	</ul>	
</body>
</html>

运行实例 »

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

3.伪类选择器

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>伪类选择器</title>
	<style>
	ul{
			padding: 0;
			margin:0;
			width:450;
			border:1px dashed #666;
			padding:10px 5px;
		}

		ul:after{
			content:'';
			display: block;
			clear:both;
		}

		li{
			list-style: none;
			float:left;
			width:40px;
			line-height: 40px;
			text-align: center;
			border-radius:50%;
			background-color: skyblue;
			margin-right:5px;
		}
		ul:before{
			content:'PHP中文网';  /*行内元素*/
		}
		ul.after{
			content: url(.../images/1.jpg);
		}

		ul li:first-child{
			background-color: brown;
		}

		ul li:last-child{
			background-color: brown;
		}
		
	</style>
</head>
<body>
	<ul>
		<li>1</li>
		<li>2</li>
		<li>3</li>
		<li>4</li>
		<li>5</li>
		<li>6</li>
		<li>7</li>
		<li>8</li>
		<li>9</li>
	</ul>	
</body>
</html>

运行实例 »

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


批改状态:合格

老师批语:作业已检查! 完成的不错!手写代码未提交!请及时提交!
本博文版权归博主所有,转载请注明地址!如有侵权、违法,请联系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+教程免费学