CSS is the Cascading Style Sheets stacked style sheet
First, the basic syntax
1, select the selection
Selector {properties: value}
Select {Property: Value}
Such as: body {color: black}
(The body section of the Body page, the Color Control of the text color properties, the value of the Black property, the effect of this example is black.)
If the value of the attribute is composed of multiple words, it must be an quoted number, such as
P {font-family: "sans serif"}
If a selector specifies multiple properties, separated by a semicolon, such as
P {text-align: center; color: black}
For easy reading, branch writing
P {text-align: center;
Color: Black;
Font-family: arial}
(The paragraph is ranked in the middle, the paragraph Chinese is black, the font is arial)
2, select the consider group
Combine the selectors of the same properties and values, separated by commas, such as
H1, H2, H3, H4, H5, H6 {Color: Green}
(All the above titles are green)
p, table {font-size: 9pt}
(Parallel and the text size of the text is 9 characters)
Equivalent to p {font-size: 9pt}
Table {font-size: 9pt}
3, class selector
If you want two different paragraphs, one to right, one place, you can define two classes first
P.right {text-align: right}
p.Center {text-align: center}
Then use in different paragraphs, just join the Class parameters you defined in the HTML tag:
paragraph to right to right p>
paragraph hidden "qi p>
The name of the class can be any English word or combination of the beginning of the English.
Another usage of the class selector is to omit the HTML tagname in the selector, which can define several different elements into the same style:
.center {text-align: center} (defined .centr is ranked in the word)
Such classes can be applied to any element, such as:
This paragraph is ranked in P>
4, ID selector
Defining the ID selection To add a "#" number before the ID name, there are two ways as the black class selection.
The following example only matches the paragraph element of ID = "INTRO":
P # INTRO
{
FONT-SIZE: 100%;
Font-weight: bold;
Color: # 0000FF
Background-Color: Transparent
}
(The font size of this paragraph is 110% of the default size; bold; blue, background color transparent)
The following example, ID attribute matches all ID = "INTRO" elements:
#intro
{
FONT-SIZE: 100%;
Font-weight: bold;
Color: # 0000FF
Background-Color: Transparent
}
5, including the selector
You can include a relationship definition for an element, and element 1 contains element 2, which is defined on element 2 in element 1, and is not defined for element 1 or element 2, such as Table A.
{
FONT-SIZE: 12PX
}
The link text in the table is 12 pixels, and the table extra linked text is still the default size.
6, the layers of style sheets
Layer is inheritance, such as nested P marks in the DIV mark:
Div {Color: Red; font-size: 9pt}
...
This paragraph text is a red 9 word
p>
div>
(The content of the P element inherits the attribute defined by the DIV)
When the inheritance of the style sheet has conflicts, the final definition is accurate, such as:
Div {Color: Red; font-size: 9pt}
P {color: blue}
...
This paragraph text is blue 9 word
p>
The text in the paragraph inherits the DIV attribute, and the Color property is in accordance with the final definition.
Priority! Important> ID Select> Class Select> Select, such as:
p. {color: # ff0000! important}
.bo {color: # 0000f}
# id1 {color: # fff00}
We also add this three styles to a paragraph, and it will finally follow it! Important declares that if you remove it! Important is yellow text according to the priority ID selection.
7, note
Note Easy to read, will not display in the browser, such as
/ * Define paragraph style * /
p
{
Text-align: center; / * text ranks in text * /
Color: Black / * text is black * /
Font-family: / * font is arial * /
}
Second, pseudo-dynamic link
1, grammar
Selector: pseudo-class {protety: value}
Select: Pseudo-class {attribute: value}
Class selection and other selectors can be mixed with pseudo-class
Selector.class: pseudo-class {protety: value}
Select. Category: Pseudo {Property: Value}
2, the anchor pseudo
Pseudo-class for the most commonly used 4 A (anchor) element
A: Link {color: # ff0000; text-decoration: none} / * Unprecedented link * /
A: visited {color: # 00ff00; Text-Decoration: none} / * Accessed link * /
A: Hover {color: # ff00ff; text-decoration: underline} / * mouse on the link * /
A: Active {color: # 0000FF; Text-Decoration: underline} / * Activation Link * /
In the above example, this link bit is accessed as red without scribing. When the access is green, there is no underline. When the activation is blue, the blue is underline, the mouse is purple on the link.
3, combination of pseudo-class and class selectors
We define a set of connects to red, the access is blue, and the other is green, and the access is yellow.
A.Red:LINK {color: # ff0000}
A.Red: Visited {color: # 0000ff}
A. Blue:link {color: # 00ff00}
A. Blue:Visited {color: # ff0000}
application
The second group connection 4, other pseudo classes
Frust-letter and Frist-line, IE 5.5 support.
P: Frist-letter {font-size: 300%}
style>
...
The first word of this paragraph is 300% of the default
p>
---------------
Div: first-line {color: red}
style>
...
The first line of this paragraph
second line
The third row
p>
div>
(The first line of paragraph is red, the second, 3 behavior default color)
Third, how to insert CSS in the web page
1, link into external style sheets, such as
...
...
hEAD>
Represents a style sheet that reads the defined defined from myStyle.css file, Rel = "Stylesheet" means the external style sheet, type = "text / cs" finger type of file is a pattern text
. HREF = "MyStyle.css" is where the file is located. An external style sheet can apply multiple pages, style sheet files can be edited with Notepad, extension is CSS.
2, internal style sheet
HR {color: sienna}
...
->
style>
hEAD>
3, import external style sheet
@Import "MyStyle.css"
Declaration of other internal style sheets
->
style>
hEAD>
Import external style sheets must be on the other internal style sheet
4, embedded style
...
p>
This paragraph color is the rough, the left distance is 20 pixels
5, multiple style table stack
priority
Inlines> Internal styles (link to external style sheets, both according to final definition determination priority> Import external style sheet
Fourth, instance analysis
1, an index.css source code analysis
Body {font-family: Song; Font-size: 9pt}
Td {font-size: 9pt} / * TD tag font is 9 * /
A: Link {text-decoration: none; color: # 000000}
A: visited {color: # 000000; Text-Decoration: none}
A: Active {color: # 000000; Text-Decoration: underline}
A: hover {color: # 000000; Text-Decoration: underline}
DIV {font-size: 9pt}
->
style>
2, a style.css source code analysis
A
{
TEXT-DECOlation: none;
A: Hover
{
COLOR: # 0099FF;
}
A: link {
Color: # 205064;
}
A: visited {
COLOR: # 006699;
}
/ * Define 4 common anchors * /
Body
{
FONT-FAMILY: Song;
FONT-SIZE: 9PT;
Text-decoration: none;
Line-height: 150%;
Background-color: #fbfdff;
}
TD
{
FONT-FAMILY: Song;
FONT-SIZE: 9PT;
}
INPUT
{
FONT-SIZE: 9PT;
HEIGHT: 20PX;
}
/ * Define the input box * /
Button
{
FONT-SIZE: 9PT;
HEIGHT: 20PX;
}
/ * Definition button * /
SELECT
{
FONT-SIZE: 9PT;
HEIGHT: 20PX;
}
/ * Definition selection box * /
.border
{
Border: 1px solid #cccccc;
}
/ * Define boundary class * /
.border2
{
Background: # fef8ed;
Border-Right: # 999999 1px solid;
Border-left: # 999999 1px Solid
}
.title
{
Background: # f6f6f6;
}
/ * Define the title class * /
.title_left
{
Background: URL (images / left_bg.gif);
}
.title_right
{
Background: URL (images / right_bg.gif);
}
/ * Define the background image of the title class * /
.title_main
{
Background: URL (images / jiaodian_bg.gif);
}
.tdbg {
Background: #fffff;
Line-height: 120%;
}
/ * Define the TD tag class * /
.tdbg_left {
Background: # fef8ed;
Line-height: 150%;
}
.tdbg_right {
Background: # eaf1fb;
Line-height: 150%;
}
.tdbg_main {
Background: #fffff;
Line-height: 150%;
}
.topborder
{
Border-Right: 1PX Solid # 6687ba;
Border-left: 1px solid # 6687ba;
Border-bottom: 1px solid # 6595d6;
Width: 760px;
}
.nav_top
{
Background-Image: URL (SKIN / 1 / TOPBG.GIF);
}
.nav_bottom
{
Background-image: URL (SKIN / 1 / BOTTOMBG.GIF);
}
.nav_menu
{
Background: URL (SKIN / 1 / TOPBAR_BG.GIF);
}
Menu
{
Background-color: # f0f9ff;
Width: 97%;
Border: 1PX;
}
/ * Define menu class * /
Td.Menubody
{
Background-color: # f0f9ff;
}
This is actually most of him based on the class selectors defined by the specific situation, and the comment has been inverted to the snake, if you want to change a style can be changed according to the class selection of the class he defined.
The attribute value of the related class selectors.
Qingfeng swordsman production, reserved all rights.
Original power network
http://www.jalih.com
E-mail: jalihh@21cn.com
->
This is what I took a word according to the previous note. I can't be described as not classic. I hope that everyone is a bit helpful. If you have the knowledge, someone else's CCS file can be seen and useful to you :) CSS Chinese manual, CSS is nothing.
I uploaded for everyone to download, address:
http://www.jagl.com.cn/soft/css2.0.chm
This very good editor TOPSTYLE LITE2.10 I often uses a few CSS examples of English comments.
I uploaded for everyone to download, address:
http://www.jagl.com.cn/soft/topstyle2.rar