CSS: Cascading Style Sheet (style sheet for short)
A style is an overall summary of the element attributes in a webpage.
When multiple CSS files are applied to HTML, if the styles defined between CSS files conflict, the style controls the content based on the hierarchy.
Basic CSS syntax:
CSS syntax includes three parts: selector, style attribute, and attribute value
Basic Syntax: Selector {proterty: value; property: value... property: Value}
Selector: the selector. All HTML tags can be used as the selector, such as body, P, and table.
Property: Property
Value: Attribute Value
CSS selection character type:
1. class selector: You can use class delimiters to classify the same elements into different styles. add a period (.) before the custom class name (.)
for example:
code highlighting produced by actipro codehighlighter (freeware)
http://www.CodeHighlighter.com/
--> P. red { color : Red }
P. blue { color : blue }
Here, P (HTML Tag) can be omitted. If it is omitted, there will be no restriction on the applicability. . Red{Color:Red}
. Blue{Color:Blue}
Reference in HTML:
< P Class = Red >
< P Class = Blue >
2. the ID selector assigns an ID Identifier to an element in an HTML document to quickly locate the element when processing the entire document, the ID selector is used to define a separate style for this element. (used only in special cases)
Syntax: Tag name # tag name {style property: value; style property: value ...}
# Salary{Color:Red}
<P id = "salary">
<! All elements with the ID of salary in section P are displayed in red.>
# Salary{Color:Red}
<Id = "salary">
<! All elements with the ID salary are displayed in red.>
3. Include the selector
The include selector is a style table defined for the element inclusion relationship (for example, element 1 contains element 2. in this way, only element 2 in element 1 is defined, and element 1 or 2 is not defined. Table B{Font-size:11px}
<! -- Set the font size of Table B. The font size of Table B is not affected.>
4. Pseudo-classes
The most extensive pseudo-classes are the four statuses of links:
A: link unlinked status
A: visited accessed link status
A: hover mouse pointer hovering over the link
A: Link Status of active (events that occur between mouse clicks and release)
On the HTML page, use the <A> tag to identify the link element.
Insert a CSS style sheet:
There are four ways to insert a CSS style table to an HTML file: external style table, internal style table, Embedded Sample table, and imported style table.
According to its location in the HTML file, it is divided into: Header, subject, external
The CSS file is defined in the HTML file header: Internal style sheet
How to define a CSS file in an HTML file subject: embed a style sheet
The CSS file is defined outside the HTML file by linking the external style table and importing the external style table.
1. link to the external style table
first, save the style table as a separate file, and then use to mark the link in the HTML file, the tag must be placed in the area of the Code .
code highlighting produced by actipro codehighlighter (freeware)
http://www.CodeHighlighter.com/
--> head
link rel =" external style table name " type =" text/CSS " href =" style table file address "
head >
Type = "text/CSS" indicates that the file type is a style sheet file.
The external style table file cannot contain any HTML tags, such as Features: an external style table file can be applied to multiple HTML files. When this style table file is changed, the style of all webpages changes accordingly.
It is suitable for creating a large number of webpages with the same style.
2. Internal Style Sheets
Use the <style> tag to directly define the content of the style sheet in the
Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/
-->
< Head >
< Style Type = "Text/CSS" >
<! --
Selector { Style attributes : Value ; Style attributes : Value ; }
Selector { Style attributes : Value ; Style attributes : Value ; }
-->
</ Style >
</ Head >
<Style> label is used to describe the style to be defined.
<! -- And --> mark is added to prevent some browsers that do not support CSS from displaying the CSS code between <style> and </style> as common strings on the webpage.
The identifier, that is, the style name. You can select all the names marked in HTML.
Feature: All the style sheet information is listed in the header of the HTML file. These style sheets can be called in the entire HTML file.
Applies to adding style sheets to webpages at a time.
3. embed a style sheet
You can directly define a style for an element by adding a style table directly to the body of the HTML code, that is, the <body> tag. < Head >
</ Head >
< Body >
< Html Mark Style = "Style property: value;>
</Body>
HTML markup is the markup of HTML elements on the page, such as body and P.
Feature: in this way, only a tag can be controlled for the style table.
It is applicable to the display style or the style of an element of a small text segment on a specified webpage.
4. Import an external style sheet
Reference an external style file in the <style> area of the style sheet. The method is similar to the method used to link the external style sheet, but @ import must be used for declaration during import. @ import is generally used in the head.
Not frequently used.