一.引入样式

1.行内样式表
<h1 style="color: red;font-size: 18px;">10-30</h1>

2.内部样式表(在head标签里面,title标签下面)
<style type="text/css">
h2{
color: yellow;
font-size: 20px;
}
</style>
优点
方便在同页面中修改样式
缺点
不利于在多页面间共享复用代码及维护,对内容与样式的分离也不够彻底

3.外部样式表
嵌入式
<link href="../css/index.css" rel="stylesheet" type="text/css"/>
导入式
<style type="text/css">
@import "../css/index.css";
</style>
嵌入式和导入式的区别:
1.<link/>标签属于XHTML,@import是属于CSS2.1
2.使用<link/>链接的CSS文件先加载到网页当中,再进行编译显示
3.使用@import导入的CSS文件,客户端显示HTML结构,再把CSS文件加载到网页当中
4.@import是属于CSS2.1特有的,对不兼容CSS2.1的浏览器是无效的

4.样式优先级
行内>内部>外部
就近原则

二.基本选择器

1.标签选择器(通过标签名称定位)
h2{
color: red;
}

2.类选择器(通过标签中class属性的值定位,值可以重复,不能以数字开头)
.class01{
color:yellow;
}
<h2 class="class01">10-30</h2>
<h1 class="class01">10-31</h1>

3.ID选择器(通过标签中id属性的值定位,值不可以重复,不能以数字开头)
#id01{
color: red;
}
<h2 id="id01">10-30</h2>
<h1 id="id02">10-31</h1>

4.基本选择器的优先级
不遵循就近原则,无论哪一种样式表的导入,都遵循:id选择器>类选择器>标签选择器

三.高级选择器

1.层次选择器
/*后代选择器*/
li p{
background-color: yellow;
}
/*子选择器*/
body>p{
background-color: aqua;
}
/*相邻兄弟*/
.class01+p{
background-color: red;
}
/*通用选择器*/
.class01~p{
background-color: blue;
}

2.结构伪类选择器

ul li:first-child{
background-color: yellow;
}
ul li:last-child{
background-color: red;
}
ul li:nth-child(even){
background-color: blue;
}
/*匹配元素类型*/
p:first-of-type{
background-color: pink;
}
p:last-of-type{
background-color: green;
}
p:nth-of-type(3){
background-color: aqua;
}

3.属性选择器
/*包含id属性*/
a[id]{
background-color: red;
}
/*包含target属性,并且值为_blank*/
a[target=_blank]{
background-color: yellow;
}
/*包含title属性,并且值以we开头*/
a[title^=we]{
background-color: aqua;
}
/*包含title属性,并且值以e结尾*/
a[title$=e]{
background-color: black;
}
/*包含class属性,并且值包含it*/
a[class*=it]{
background-color: blue;
}

最新文章

  1. idea中配置eslint 静态代码检查
  2. EntityFramework系列:SQLite.CodeFirst自动生成数据库
  3. video 与 audio
  4. JS表单设置值
  5. JavaScript强化教程——Cocos2d-JS中JavaScript继承
  6. dojo 十二 rest
  7. Android中的BroadCast静态注册与动态注册
  8. Building,Packaging,Deploying,and Administering Applications and Types
  9. FFT算法的物理意义
  10. UVa 143 - Orchard Trees
  11. eclipse项目中丢失的R包找回方法
  12. dede标签:定义文件夹
  13. 和菜鸟一起学linux之initramfs方式启动
  14. 学会这15点,让你分分钟拿下Redis数据库
  15. Linux bash基础特性二
  16. 浅谈UI自动化测试
  17. 终端简单使用 &amp;vim编写代码
  18. j2ee高级开发技术课程第八周
  19. mysql修改存储过程的权限
  20. (转)引用---FFMPEG解码过程

热门文章

  1. Java面向对象编程 -3.2
  2. 刚开始用springboot踩的好多坑!!!
  3. adblock广告过滤
  4. Python实现图片识别加翻译【高薪必学】
  5. 03.使用私有构造方法或枚类实现 Singleton 属性
  6. NB-IoT的介绍最终版 !看明白了吗?(转自 top-iot)
  7. 吴裕雄 Bootstrap 前端框架开发——Bootstrap 排版:设定文本居中对齐
  8. LeetCode 19. Remove Nth Node From End of List(删除链表中倒数第N个节点)
  9. SRS命令
  10. Python 面试问答基础篇