1, css:cascading style Sheet (cascading style sheet).
2. CSS Grammar rules:
(1) Two main components: selector, and one or more declarations.
A selector is a pointer to an HTML element that needs to define a style, and a declaration consists of a property and its corresponding value.
{property: Value}
If you have more than one declaration, you need to separate each declaration with a semicolon.
{ text-align:Center; color:red;}
If multiple selectors can have the same style description, they can be declared together, and multiple selectors are separated by commas.
{ color: green; font-family: Verdana;}
3. Derivation Selector
Li Span { color:blue;}
<P><span>I'm not blue.</span></P><ul> <Li>I'm not blue either.</Li> <Li><span>I am the Blue</span></Li></ul>
Styles are only valid for span labels in li.
4. ID selector, class selector, property selector
(1) An id attribute can be specified for a tag element in an HTML file, and the attribute value belongs to only that element, that is, there can be only one element of the same ID in the HTML file. The ID can be specified in the CSS using the "#" reference.
The HTML file can also specify a class attribute for one or more elements, which can be used in CSS through the "." The reference specifies the class element.
{ font-size:30px; text-align:Center; color:#000; } . setred { color:red;} . Setblue { color:blue;}
<DivID= "header"> <P>Header</P></Div><Div> <Pclass= "Setred">P1</P> <Pclass= "Setblue">P2</P> <Pclass= "Setred">P3</P> </Div>
(2) CSS can also be styled for HTML elements that have the specified properties, but only in the rules! DOCTYPE, it is possible for browsers above IE7.
[title] { color: red;} /* valid only for elements with the title property */
< P title = "PPPP" > CSS effective </p><href= "http://sina.com> CSS invalid </a><span title= "ssss">css effective </span >
The property selector can also match the property values to set the style:
[Title=w3school] { border:1px solid blue;}
You can also match multiple property values, and the following example sets the style for elements that include the Hello element in the Title property:
[Title~=hello] { color:red;}
<H1>You can apply styles:</H1><H2title= "Hello World">Hello World</H2><Ptitle= "Student Hello">Hello W3school students!</H1><HR/><H1>Cannot apply style:</H1><H2title= "World">Hello World</H2><Ptitle= "Student">Hello W3school students!</P>
The
Sets the style for the form:
input[type= "text"] { width : 150px ; display : block ; Margin-bottom : 10px ; Background-color : yellow ; font-family : Verdana, Arial ;} input[type= "button"] {: 120px ; Margin-left : 35px ; display : block ; font-family : Verdana, Arial ;}
5. CSS Creation
(1) External style sheet
Create a CS file (with the extension CSS) and reference it in the HTML file via the link tag in the header:
(2) Internal style sheet
Set with the Style tab in the HTML header:
< Head > < type= "stylesheet"> p{: } span{.. }}
(3) Inline style
Set directly through the style in the element that you want to set:
<style= "Text-align:center;color: #ccc"> text </p>
CSS Basics Tutorial Essentials Notes