惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - Na57

ASP.NET MVC应用中一个诡异错误的处理 使用Enterprise Library 4.0 Logging 的问题 8. Action过滤 6. 视图和生成助手 5. 控制器和Action方法 2. 创建基本的MVC项目 3. URL路由 - Na57 - 博客园 4. 用MVC实现URL路由 Google笔记本迈向烂笔头 XML and Databases 笔记 烂笔头又来了 - Na57 - 博客园 <程序员>200711期算法擂台的解答 GeoServer抛异常IllegalArgumentException的原因 关于CSS中float属性的理解 ItemCreated与ItemDataBound 《SAML简介:安全地共享数字身份信息》读后感 JavaScript 学习(2) - JS的内建对象 JavaScript from C#(入门篇) 2006.6《程序员》笔记
CSS学习
Na57 · 2006-11-02 · via 博客园 - Na57

入门

介绍

CSS的出现解决了一个问题: 内容与表现的分离.

当一个元素受到多个CSS效果的影响时, 存在一个影响规则:

1.       Browser default

2.       External style sheet

3.       Internal style sheet (inside the <head> tag)

4.       Inline style (inside an HTML element)

其中, d 的优先级最高.

语法

基本语法

一个CSS片断由3个部分组成: 选择器(selector), 属性, . 选择器表示谁讲受这段CSS影响.:

    body {color: black}

如果值由多个词组成,则需要使用引号, :

 p {font-family: "sans serif"}

如果需要指定多个属性值, 则需要使用分号分隔. :

p {text-align:center;color:red}
注意:属性值的数字与单位之间不能有空格.: "margin-left: 20px" 不能写成"margin-left: 20 px"
 

父子选择器

div p (color:red)
匹配div下的p元素节点.

分组

当多个选择器都使用同一个CSS效果时, 可以使用分组以节省代码. :

h1,h2,h3,h4,h5,h6 
{
color: green
}

与分组相反, 相同的元素需要使用不同的效果时, 需要使用类选择器. :

p.right {text-align: right}
p.center {text-align: center}
<p class="right">This paragraph will be right-aligned.</p>
<p class="center">This paragraph will be center-aligned.</p>

有些时候, 一些类是对多个元素通用的, 这时候可以忽略元素的名称. :

.center {text-align: center}

id 选择器

可以使用id选择器为特定的节点分配CSS. 用法类似类选择器. :

#green {color: green}
p#para1
{
text-align: center;
color: red
}

注释

类似C语言, 使用 “/**/” 进行注释.

How to

可以在三个地方编写CSS:

外部.css文件

<head>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
</head>

html内部的样式表元素中

<head>
<style type="text/css">
hr {color: sienna}
p {margin-left: 20px}
</style>
</head>

元素的style属性

    <p style="color: sienna; margin-left: 20px">This is a paragraph</p>
注意:如果一个节点被多个CSS效果影响,则使用继承原则 能保留的保留,不能保留的就覆盖.

背景

留做参考

文本

留做参考

字体

留做参考

边框

留做参考

对象间隙

留做参考

边界距离

留做参考

关于对象,边框,对象间隙与边界距离,可以根据下图进行区别:

图片来自于: http://edu.chinaz.com/Get/Website/Html_Css/06121355133452315.asp

列表

留做参考

高级

维度

维度定义了一组用于控制对象高度与宽度的属性. 可惜的是, 大部分属性是IE不支持的.

显示

位置

伪类

伪类用来给一些元素添加特定的效果.

声明一个伪类的语法如下:

selector:pseudo-class {property: value}

也可以为一个类声明伪类. :

selector.class:pseudo-class {property: value}

超链接的伪类

这是平时最常见的伪类:

a:link {color: #FF0000}     /* unvisited link */
a:visited {color: #00FF00}  /* visited link */
a:hover {color: #FF00FF}   /* mouse over link */
a:active {color: #0000FF}   /* selected link */

有一点要注意: hover必须在linkvisited后面, active必须再hover后面.

first-child 伪类

它有三种用法:

1.      div > p:first-child
匹配任何一个div元素的第一个p元素.
2.      p:first-child em
匹配任何一个p元素的第一个em元素.
3.      a:first-child
匹配任何一个元素的第一个a元素.

lang伪类

为特定的lang属性值提供效果.例如:
q:lang(no)
{
quotes: "~" "~"
}
以上示例匹配一个lang属性值为noq元素.
 
focus伪类
此伪类为CSS2标准,目前没有任何浏览器实现了它.

伪元素