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. Java中的return

    比如你写了一个叫getInt的类public int getInt(){ //这个类的意思就是一个具有返回值类型为int的类了 //通常如果不需要返回值的话 这里就写void....//你的具体代码r ...

  2. 瞬间从IT屌丝变大神——分工安排

    分工安排主要包含以下内容: 公共组件(包括common.css和common.js)一人维护,各子频道专人负责,每个频道正常情况下由一人负责,要详细写明注释,如多人合作,维护的人员注意添加注释信息,具 ...

  3. 机器学习中的数学(3)-模型组合(Model Combining)之Boosting与Gradient Boosting

    版权声明: 本文由LeftNotEasy发布于http://leftnoteasy.cnblogs.com, 本文可以被全部的转载或者部分使用,但请注明出处,如果有问题,请联系wheeleast@gm ...

  4. 内核源码分析之linux内核栈(基于3.16-rc4)

    在3.16-rc4内核源码中,内核给每个进程分配的内核栈大小为8KB.这个内核栈被称为异常栈,在进程的内核空间运行时或者执行异常处理程序时,使用的都是异常栈,看下异常栈的代码(include/linu ...

  5. [转]Erlang不能错过的盛宴

    Erlang不能错过的盛宴 (快步进入Erlang的世界) 作者:成立涛 (litaocheng@gmail.com) 作为程序员,我们曾经闻听很多“业界动态”,“技术革新”,曾经接触很多“高手箴言” ...

  6. 单词计数WordCountApp.class

    public class WordCountApp { // 可以指定目录,目录下如果有二级目录的话,是不会执行的,只会执行一级目录. private static final String INPU ...

  7. CSS构造超链接

    超链接边框 派生超链接 属性选择器超链接 动态超链接 图像翻转超链接 CSS工具提示 1.给链接加上边框     A:link {         Color: #f00;         Text- ...

  8. ElasticSearch中文分词(IK)

    ElasticSearch常用的很受欢迎的是IK,这里稍微介绍下安装过程及测试过程.   1.ElasticSearch官方分词 自带的中文分词器很弱,可以体检下: [zsz@VS-zsz ~]$ c ...

  9. C# winform 最小化到电脑右下角

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  10. MATLAB代码

    clear;clc%%%%%%%%%%%%方程里的参量%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%alpha=0.5;beta=0.5;%%% ...