1. What is CSS
CSS Cascading style sheet (full name: Cascading style Sheets) is a computer language used to represent file styles such as HTML or XML. CSS3 is an upgraded version of CSS2, 3 is the version number, it adds a lot of powerful new features on the basis of CSS2.1. At present, the mainstream browser Chrome, Safari, Firefox, Opera, and even 360 have supported most of the CSS3 features, IE10 also began to fully support CSS3. Different browsers may require a different prefix. It indicates that the CSS property or rule has not yet become part of the World Wide Web Standard, is the browser's private property, although the newer version of the browser does not need a prefix, but in order to better forward compatibility prefix is not necessary.
-moz-transform:translatex (20px);-webkit-transform:translatex (20px);-ms-transform:translatex (20px); Transform: TranslateX (20px);
Transform is a new property for CSS3, and each browser needs to add a prefix to support it.
What 2.CSS can do
- Style defines how HTML elements are displayed.
- CSS has a lot of effects, even animations, that need to be done before using images and scripts, and it takes just a few lines of code. such as rounded corners, picture borders, Text shadows and Box shadows, transitions, animations and so on.
- CSS simplifies the design process for front-end development workers, more flexible page layouts, and faster page loading times.
- You can use a CSS file to control all the Web page styles on the site, as long as you modify the corresponding code in the CSS file, then all pages of the entire site will be changed.
- Objective: To separate the performance from the structure.
/**body{ background-color:#ccc;} H1 { font-size:16px; font-family:"Microsoft Jas Black"; font-weight:normal;}
<!--index.html -<Head> <Linkrel= "stylesheet"href= "./style.css"></Head><Body> <H1>This is the title</H1></Body>
3.CSS syntax structure
CSS rules consist of two main parts: selectors, and one or more declarations, selectors are usually HTML elements that you need to change the style. Each declaration consists of an attribute and a value. The property is the style property (style attribute) that you want to set. Each property has a value. Attributes and values are separated by colons.
P { /** * color:red; /* */}
4. How to introduce CSS
There are three ways to introduce style sheets:
- External style sheet
- Internal style sheet
- inline style
4.1 External style Sheets
An external style sheet is an ideal choice when the style needs to be applied to many pages. With an external style sheet, you can change the appearance of the entire site by changing a file. Each page uses <link> tags to link to the style sheet. <link> tags at the head of (document):
4.2 Internal style sheet
An internal style sheet should be used when a particular style is required for a single document. You can use the <style> tag to define an internal style sheet at the head of the document.
{ color:red; } </style>
4.3 Inline style
Inline style refers to the style attribute that writes CSS styles directly to the HTML tag. Note that the introduction of CSS in this way is not required to write selectors.
<p style= "color:red;" > This is a paragraph </p>
4.4 Priority comparisons of three introduction methods
What style is used when the same HTML element is defined by more than one style? Generally, all styles are stacked in a new virtual style sheet according to the following rules, where the number 4 has the highest precedence.
- Browser default settings
- External style sheet
- Internal style sheet (inside the
- Inline style (inside HTML elements)
Therefore, the inline style (inside the HTML element) has the highest precedence, which means that it takes precedence over the style declaration in the label, the style declaration in the external style sheet, or the style declaration in the browser (the default).
5.CSS Code Comment
CSS code comments, start with/*/end.
/* Public Style */ { margin:0px; padding:0px;} /* navigation style start */ {... } /* end of navigation style */
6.CSS Selector
The CSS selector is used to select the mode of the element you want to style.
6.1 Wildcard Selector
* Selector selects all elements. * The selector can also select all elements within another element:
* { /**/ margin:0; Padding:0;} Div * { /**/ color:blue;}
6.2 Element Selector
The so-called element selector, which refers to the name of an existing label in a Web page as a selector.
Body { /**/ font-size:16px;} a { /**/ text-decoration:none;}
6.3 Group Selector
In addition to styling a single label, you can make the same style definition for a group of labels. Separates the selectors with commas. To use elements of the same style on a page, just write the style once.
h1,h2,h3,p { font-size:16px; color:red;}
CSS (i): Understanding CSS