css的9个常用选择器
1.类选择器(通过类名进行选择)
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style type="text/css">
.p1{
color: #00ff00;
}
.p2{
color: #0000ff;
}
</style>
<body>
<p class="p1">这是类选择器</p>
<p class="p2">hello world</p>
</body>
</html>
效果图:

2.id选择器(通过id进行选择)
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style type="text/css">
#text{
color: red;
}
</style>
<body>
<p id="text">这是id选择器</p>
</body>
</html>
效果图:

3.标签选择器(通过id进行选择)
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style type="text/css">
p{
color: #f40;
font-size: 25px;
}
</style>
<body>
<div>
<p>这是标签选择器</p>
</div>
</body>
</html>
效果图:

4.分组选择器(可一次选择多个标签以设置相同样式)
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style type="text/css">
p,a,li{
color: blue;
}
</style>
<body>
<p>这是分组选择器</p>
<p>hello</p>
<a href="#">world</a>
<div>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
</body>
</html>
效果图:

5.后代选择器(选择某个标签的所有后代以设置相同样式)
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style type="text/css">
div ul li{
color: red;
list-style: none;
}
</style>
<body>
<div>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
</ul>
</div>
</body>
</html>
效果图:

6.属性选择器(通过属性(如name属性)进行选择以设置相同的样式)
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style type="text/css">
[name="pra1"]{
color: blue;
}
[name="pra2"]{
color: red;
}
</style>
<body>
<p name="pra1">这是属性选择器</p>
<p name="pra2">hello world</p>
</body>
</html>
效果图:

7.通用选择器(选择所有标签以设置相同样式)
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style type="text/css">
*{
color: red;
}
</style>
<body>
<p>这是通用选择器</p>
<p>hello</p>
<p>world</p>
</body>
</html>
效果图:

8.兄弟选择器(选择兄弟关系的标签设置样式)
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style type="text/css">
p+a{
color: green;
}
</style>
<body>
<p>这是兄弟选择器</p>
<a>hello world</a>
</body>
</html>
效果图:

9.直接父子选择器(选择父子关系的标签中子标签设置样式)
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style type="text/css">
div>p {
color: red;
}
</style>
<body>
<div>
<p>这是直接父子选择器</p>
</div>
</body>
</html>
效果图:

css的9个常用选择器的更多相关文章
- CSS常用选择器
关于CSS常用选择器: 1.ID选择器 关于ID选择器具有唯一性,在文档流中,ID是唯一的,在低版本的浏览器中,允许出现不适唯一ID的情况,而在高版本的浏览器中,出现ID不唯一的情况浏览器会出现的报错 ...
- CSS选择器详解(一)常用选择器
目录 类型选择器 类选择器 ID选择器 伪类 伪元素 类型选择器 通过类型选择器可以选择某一类型的html标签,并对其使用样式. 语法: selector {property1: value; pro ...
- HTML&CSS基础-常用选择器
HTML&CSS基础-常用选择器 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.html源代码 <!DOCTYPE html> <html> & ...
- css的书写规范+常用
格式化: body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,textarea,p,blo ...
- css基础语法一(选择器与css导入方式)
页面中,所有的CSS代码,需要写入到<style></style>标签中.style标签的type属性应该选择text/css,但是type属性可以省略. CSS修改页面中的所 ...
- jQuery常用选择器总结
jQuery常用选择器总结: 我们都知道jQuery是JavaScript(JS)的框架,它的语法简单使用方便,被广大开发人员青睐.现在我就它常用的并且十分强大的选择器的方式,做一个总结.鉴于它的选择 ...
- 学习总结:CSS(一)定义方式、选择器、选择器权重
一.CSS的定义方式 1.内部样式:<style></style> 2.行间样式:<div style="width:100px;height:100px;&q ...
- 【3-24】css样式表分类、选择器、样式属性
一.css样式表分类: (一)内联样式表:代码写在标签内的样式表 控制精确 代码重用性差 优先级最高 格式:<p style="样式属性">内容</p> ...
- 01-css的引入方式和常用选择器
一.css介绍 现在的互联网前端分三层: HTML:超文本标记语言.从语义的角度描述页面结构. CSS:层叠样式表.从审美的角度负责页面样式. JS:JavaScript .从交互的角度描述页面行为 ...
随机推荐
- linux性能分析工具Sysstat
- Redis线上环境做Keys匹配操作!你可以离职了!
转自:https://blog.csdn.net/bntx2jsqfehy7/article/details/84207884一.一个新闻 新闻内容如下:php工程师执行redis keys * 导致 ...
- nginx日志切割脚本shell
nginx-log-rotate.sh: #!/bin/bash#---------------------------------------------# Comment:Used for rot ...
- 一、Api
一. private static readonly IList<string> BaseParamKey = new List<string>() { "apiId ...
- 【LeetCode】抽样 sampling(共4题)
第一部分 水塘抽样 reservoir sampling 水塘抽样的原理:(应该开一篇新文章)pssss [382]Linked List Random Node (2018年11月15日,新算法) ...
- Go copy 的使用
copy 可以将后面的 第2个切片的元素赋值copy 到第一个切片中 package main; import "fmt" func test () { s1 := []int{1 ...
- boost bimap
The library Boost.Bimap is based on Boost.MultiIndex and provides a container that can be used immed ...
- shell脚本学习 (8) fmt 格式化段落
1 获取系统中的字典文件 -n隐藏查找过程 -e 匹配多次,只打印带p的行(不能写成-e -n) ,100p /usr/share/dict/words 会显示1-100行的字母 2 fmt 按默认 ...
- Tortoise git账号记住密码
方法一: 本地git仓库目录下,找到 .git/config ,然后打开增加: [credential] helper = store 这样只有该目录下的git操作不用每次输入用户名和密码,换一个目录 ...
- php基于SQLite实现的分页功能示例
php基于SQLite实现的分页功能. 这里操作数据库文件使用的是前面文章<PHP基于PDO实现的SQLite操作类>中的SQLite数据库操作类. 代码: <?php class ...