1.

(1)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>选择器</title>
<link rel="stylesheet" href="my.css" type="text/css"/>
</head> <body>
你好,北京!
<span class="style1" id="special_new">新闻1</span>
<span class="style1">新闻2</span>
<span class="style1">新闻3</span>
<span class="style1">新闻4</span>
<span class="style1">新闻5</span> <span id="style2">这是一则<span>非常重要</span>的新闻</span><br /> <a href="#">goto sohu</a><br />
<a href="#">goto sina</a><br />
</body>
</html>

(2).my.css文件如下:

@charset "utf-8";
/* CSS Document */ /*html的选择器*/
body {
color:orange;
} a:link {
color:black;
text-decoration:none;
} a:hover {
text-decoration:underline;
} a:visited {
color:red;
} /*.style1 就是类选择器*/
.style1 {
font-weight:bold;
font-size:20px;
background-color:pink;
color:black;
} #special_new {
font-style:italic;
color:red;
} /*#style2就是id选择器*/ #style2 {
font-size:30px;
background-color:silver;
color:black;
} /*#style2 span 就是父子选择器, #style2是父,span是子*/
#style2 span {
font-style:italic;
color:red;
} /*#style2 span 就是父子选择器, #style2是父,span是子,也包含层次关系*/
#style2 span span{
font-size:50px;
}

如果一个元素被id和class同时修饰时,id选择器的优先级>class选择器

2.一个元素最多有一个id选择器,但是可以有多个类选择器

(1)html文件:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>选择器</title>
<link rel="stylesheet" href="my.css" type="text/css"/>
</head> <body>
你好,北京!
<span class="style1" id ="special_new">新闻1</span>
<span class="style1">新闻2</span>
<span class="style1 style4">新闻3</span>
<span class="style1">新闻4</span>
<span class="style1">新闻5</span> <span id="style2">这是一则<span>非常重要</span>的新闻</span><br /> <a href="#">goto sohu</a><br />
<a href="#">goto sina</a><br />
</body>
</html>

这里"新闻3"修饰的是两个.class类,如果修饰发生冲突,到底哪个为准呢?

(2)my.css文件

@charset "utf-8";
/* CSS Document */ /*html的选择器*/
body {
color:orange;
} a:link {
color:black;
text-decoration:none;
} a:hover {
text-decoration:underline;
} a:visited {
color:red;
} /*.style1 就是类选择器*/
.style1 {
font-weight:bold;
font-size:20px;
background-color:pink;
color:black;
font-style:normal;
} .style4 {
font-style:italic;
text-decoration:underline;
color:green;
} #special_new {
font-style:italic;
color:red;
} /*#style2就是id选择器*/ #style2 {
font-size:30px;
background-color:silver;
color:black;
} /*#style2 span 就是父子选择器, #style2是父,span是子*/
#style2 span {
font-style:italic;
color:red;
} /*#style2 span 就是父子选择器, #style2是父,span是子,也包含层次关系*/
#style2 span span{
font-size:50px;
}

这里基准是:在css文件中,那个.class文件在后面定义的,就显示它的效果:比如这里的.style4定义在.style1后面,所以以.style4效果为准

3.

--->在引用多个class选择器时候,用空格隔开

--->当class选择器发生冲突时候,在css文件中,最后出现的class选择器样式为准

css笔记09:选择器优先级的更多相关文章

  1. CSS学习之选择器优先级与属性继承

    CSS学习之选择器优先级与属性继承 选择器优先级 其实选择器是具有优先级的,我们来看下面这一组案例: <!DOCTYPE html> <html lang="en" ...

  2. 第17天:CSS引入、选择器优先级(中级)

    一.CSS 位置 1.行内式  css <div class="fr" style="color:red;">aa</div> 2. 内 ...

  3. CSS笔记——属性选择器

    1.存在和值(Presence and value)属性选择器这些属性选择器尝试匹配精确的属性值:[attr]:该选择器选择包含 attr 属性的所有元素,不论 attr 的值为何.[attr=val ...

  4. CSS中选择器优先级与!important权重使用

    CSS中的选择器优先级与!important权重使用 .class选择器要高于标签选择器. #id选择器要高于.class选择器. 标签选择器是优先级最低的选择器. !important的属性它的权重 ...

  5. CSS:CSS样式表及选择器优先级总结

    我们在写网页的时候经常会遇到同一个HTML文件,使用了外部样式.内部样式以及内联样式,那么如果发生冲突时浏览器是怎么抉择的呢? 也会遇到这样的情况,在样式表中,对同一个HTML元素,我们有可能既用到了 ...

  6. CSS选择器优先级总结

    CSS三大特性-- 继承. 优先级和层叠. 继承:即子类元素继承父类的样式; 优先级:是指不同类别样式的权重比较; 层叠:是说当数量相同时,通过层叠(后者覆盖前者)的样式. css选择符分类 首先来看 ...

  7. css知多少——选择器的优先级

    1. 引言 上一节<css知多少(5)--选择器>最后提到,选择器类型过多将导致一些问题,是什么问题呢?咱们直接举例子说明. 上图中,css中的两个选择器都是针对<span>的 ...

  8. CSS样式选择器优先级

    CSS样式选择器分为4个等级,a.b.c.d,可以以这四种等级为依据确定CSS选择器的优先级. 1.如果样式是行内样式(通过Style=””定义),那么a=12.b为ID选择器的总数3.c为Class ...

  9. 【CSS系列-选择器优先级总结】

    转:http://www.cnblogs.com/dolphinX/p/3511300.html 容易被忽略CSS特性   CSS初学感觉很简单,但随着学习的深入才感觉CSS的水由多深,平常总会遇到各 ...

随机推荐

  1. MFC学习知识点20160715

    1.   sizeof()  :返回所查询目标所占用字节数 _countof() :返回所查询目标所含有元素个数 _countof 是 C++中计算一个固定大小数组长度的宏,比如: T arr[10] ...

  2. 《Genesis-3D开源游戏引擎完整实例教程-2D射击游戏篇06:计分》

    6.计分 计分概述: 分值计量直接反应玩家在游戏中获得的成就感.因此,计分系统在游戏中显得尤为重要,有的反应在直接获取的分数上,有的反应在杀敌数量上等. 计分原理: 原理图,如图6-1所示. 图6-1 ...

  3. poj1000 A+B Problem

    Description Calculate a+b Input Two integer a,b (0<=a,b<=10) Output Output a+b Sample Input 1 ...

  4. HDU5734:Acperience(方差)

    题意: 给出n个数xi,确定一个值α,使得Σ(xi-α)^2的值最小. 分析: 可以猜想是方差,不懂得可以去方差了解一下. 那么α即为∑(xi)/n,然后要注意的是转化为分数,首先我们不能用小数转分数 ...

  5. [转]解决百度统计 gzdecode(): insufficient memory

    百度统计API gzdecode($preLogin->retData, strlen($preLogin->retData)) 这段代码会造成一个PHP警告内存不足,解决办法只要换个解压 ...

  6. thymeleaf中的th:remove用法

    一.删除模板片段使用th:remove属性 th:remove的值如下: 1.all:删除包含标签和所有的孩子. 2.body:不包含标记删除,但删除其所有的孩子. 3.tag:包含标记的删除,但不删 ...

  7. thymeleaf中的th:assert用法

    th:assert 断言标签 th:assert属性可以指定一个以逗号分隔的表达式对其进行评估并生产适用于每一个评价,如果不抛出异常 <div th:assert="${onevar} ...

  8. codeforces300A Array

    A. Array time limit per test 2 seconds memory limit per test 256 megabytes input standard input outp ...

  9. [iOS UI进阶 - 2.4] 彩票Demo v1.4 转盘动画

    A.需求 幸运广场界面中有一个幸运转盘,平时能够自动缓缓转动 能够选择星座 点击“开始选号”开速旋转转盘,旋转一定周数 转盘转动速度节奏:开始-慢-块-慢-结束 设置其余的背景和按钮   code s ...

  10. UVaLive 6625 Diagrams & Tableaux (状压DP 或者 DFS暴力)

    题意:给一个的格子图,有 n 行单元格,每行有a[i]个格子,要求往格子中填1~m的数字,要求每个数字大于等于左边的数字,大于上边的数字,问有多少种填充方法. 析:感觉像个DP,但是不会啊...就想暴 ...