一、CSS代码构成
-
CSS是什么?
-
CSS(样式)
-
Cascading Style Sheets
-
用来定义页面元素样式
- 设置字体和颜色
- 设置位置和大小
- 添加动画效果
-
CSS代码基本组成
-
二、CSS使用方法
-
在页面中使用CSS
-
外链
-
<link rel="stylesheet" href="/路径.css">
-
-
嵌入
-
<style> li{ margin: 0; list-style: none; } p{ margin: lem 0; } </style>
-
-
内联
-
<p style=" margin:lem 0">Example Content </p>
-
-
-
CSS是如何工作的
-
选择器Selector
-
找出页面中的元素,以便给他们设置样式
-
使用多种方式选择元素
- 按照标签名、类名或id
- 按照属性
- 按照DOM树中的位置
-
-
通配选择器
-
<style> *{ color: red; font-size: 20px; } </style>
-
-
标签选择器
-
<style> h1 { color: orange; } p{ color: gray; font-size: 20px; } </style>
-
-
id选择器
-
<style> #logo { font-size: 60px; font-weight: 200; } </style>
-
-
类选择器
-
<style> .done { color: gray; text-decoration: line-through; } </style>
-
-
属性选择器
-
<style> [disabled] { background: #eee; color: #999; } </style>
-
-
伪类选择器
-
<style> a:link { color: black; } a:visited { color: gray; } </style>
-
-
组合
-
三、CSS流程之选择器组、文本渲染
-
选择器组
-
body, h1, h2, h3, h4, h5, h6, ul, ol, li { margin: 0; padding: 0; }
-
-
颜色-RGB
-
颜色-HSL
-
Alpha 透明度
-
字体font-family
-
<style> h1 { font-family: Optima, Georgia, serif; } body{ font-family: Helvetica, sans-serif; } </style>
-
-
通用字体族
-
四、调试CSS
-
右键点击页面,选择【检查】
-
使用 快捷键
- Ctrl+Shift+I(windows)
- Cmd+Opt+I(mac)