博主信息
博文 64
粉丝 2
评论 1
访问量 58963
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
基本选择器和属性选择器——2018年3月21日
Y的博客
原创
754人浏览过

代码基本选择器

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>基本选择器</title>
	<style type="text/css">
    #name { background-color: red; }
    #sex {background-color: black;}
    .xq { background-color:yellow; }
    table *{ background-color:lightgreen; color: white;}
    tr th { color: green; }
    #sex+td { background-color:blue; }
    #sex~td { background-color:blue; }
</style>
</head>
<body>
	<table border="0" cellspacing="0" cellpadding="5" align="center" width="60%">
		<tr>
			<th id="name">姓名</th>
			<th id="sex">性别</th>
			<th class="age">年龄</th>
			<th class="xq">兴趣</th>
		</tr>
		<tr><td colspan="4"><hr></td></tr>
		<tr>
			<td id="name">张三</td>
			<td id="sex">男</td>
			<td class="age">21</td>
			<td class="xq">打篮球</td>
		</tr>
		<tr><td colspan="4"><hr></td></tr>
		<tr>
			<td id="name">李四</td>
			<td id="sex">男</td>
			<td class="age">23</td>
			<td class="xq">羽毛球</td>
		</tr>
		<tr><td colspan="4"><hr></td></tr>
		<tr>
			<td id="name">张漂亮</td>
			<td id="sex">女</td>
			<td class="age">21</td>
			<td class="xq">打排球</td>
		</tr>
	</table>
</body>
</html>

运行实例 »

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

代码属性选择器

实例

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>属性选择器</title>
	<style type="text/css">
   *[id] {background-color: red;}
   tr [ class="age"] {background-color: blue;}
   tr [ class~="sex"] {background-color: green;}
   tr [ class^="xq"] {background-color: skyblue;}
   tr [ class^="xq"] {background-color: skyblue;}
   tr [ class$="y"] {background-color: #00EE76;}
   tr [ class*="j"] {background-color: #B22222;}

</style>
</head>
<body>
	<table border="0" cellspacing="0" cellpadding="5" align="center" width="60%">
		<tr align="center">
			<th id="name">姓名</th>
			<th class="sex">性别</th>
			<th class="age">年龄</th>
			<th class="xq">兴趣</th>
			<th class="zy">职业</th>

		</tr >
		<tr><td colspan="5"><hr></td></tr>
		<tr align="center">
			<td id="name">james</td>
			<td class="sex">男</td>
			<td class="age">32</td>
			<td class="james">打篮球</td>
			<td class="zy">篮球运动员</td>
		</tr>
		<tr><td colspan="5"><hr></td></tr>
		<tr align="center">
			<td id="name">李四</td>
			<td class="sex">男</td>
			<td class="age">23</td>
			<td class="xq">羽毛球</td>
			<td class="zy">学生</td>
		</tr>
		<tr><td colspan="5"><hr></td></tr>
		<tr align="center">
			<td id="name">张漂亮</td>
			<td class="sex">女</td>
			<td class="age">21</td>
			<td class="xq">打排球</td>
			<td class="zy">学生</td>
		</tr>
	</table>
</body>
</html>

运行实例 »

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

QQ图片20180322101850_副本.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+教程免费学