Study 5--CSS Overview

Source: Internet
Author: User

css (cascading style Sheet) is called a cascading style sheet, or it can be called a CSS style sheet or style sheet with a. css file name extension.
CSS is a markup language that enhances or controls the style of a Web page and allows the separation of style information from the content of the Web page.
The purpose of referencing a style sheet is to leave the page structure code and page style style code separated to have more control over the layout of the page.

CSS Basic Syntax
A CSS style sheet consists of several style rules, each consisting of three parts:
Selectors (selector), property, and property values (value),
The basic format is as follows:
Selector{property:value;}

the way CSS style sheets Control HTML5 page effects typically includes inline styles, inline styles, link styles, and import styles.
Link Style:
<link rel= "stylesheet" type= "Text/css" href= "1.css"/>
(1) rel = link to style sheet with a value of stylesheet
(2) type indicates that the style sheet type is a CSS style sheet
(3) href Specifies the path to the CSS style sheet file, which indicates that the name is 1.css file under the current path. This path uses both absolute and relative paths, depending on the situation.
Import Style:
importing an external style sheet refers to importing an external CSS file using @import in the <style> tag of the inline style sheet, such as:

<style type= "Text/css" >
@import "1.css"
</style>


Priority level:
the precedence order of CSS style sheets is from large to small: inline style, inline style, link style, import style.

CSS Selector (selector selector)
depending on the CSS selector, the selector can be divided into tag selectors, class selectors, global selectors, ID selectors, pseudo-class selectors, and so on.
Global Selector
If you want all of the HTML tags in a page to use the same style, you can use the global selector, syntax format:
*{property:value;}
Pseudo class
a:link/* Non-accessible links * /
a:visited/* Visited link * /
a:hover/* Mouse move to link * /
a:active/* Selected link * /

structure Pseudo-class selector
selector meaning
E:root matches the root element of the document, which is the HTML element for the HTML document
E:nth-child (n) matches the nth child element of its parent element, and the first number is 1
E:nth-last-child (n) matches the reciprocal nth child element of its parent element, the first number is 1
e:nth-of-type (n) works similarly to: Nth-children (), but only matches elements that use the same label
e:nth-last-of-type (n) works similarly to: Nth-last-child (), but only matches elements that use the same label
E:last-child matches the last child element of the parent element, equivalent to: Nth-last-child (1)
E:first-of-type matches the first child element of the same label under the parent element, equivalent to: Nth-of-type (1)
E:last-of-type matches the last child element of the same label under the parent element, equivalent to: Nth-last-type (1)
E:only-child matches only one of the child elements under the parent element, equivalent to: First-child:last-child or: Nth-child (1): Nth-last-child (1)
E:only-of-type matches the only child element that uses the same label under the parent element, equivalent to: First-of-type:last-of-type or: Nth-of-type (1): Nth-last-of-type (1)
E:empty matches an element that does not contain any child elements, note that the text node is also considered a child element
Example:
<! DOCTYPE html>


<meta charset= "UTF-8" >
<title> structure Pseudo-class </title>
<style>
Tr:nth-child (even) {
background-color: #f5fafe;
}
tr:last-child{
font-size:25px;
}
Li:nth-child (3) {
color:red;
}
</style>

<body>
<table border= "1" width= "15%" >
<th> name </th><th> number </th><th> gender </th>
<tr><td> Liu Haisong </td><td>006</td><td> men </td></tr>
<tr><td> Wang Feng </td><td>001</td><td> women </td></tr>
<tr><td> Li Zhangli </td><td>006</td><td> men </td></tr>
<tr><td> Liu Haisong </td><td>006</td><td> men </td></tr>
</table>
<ul>
<li> Vegetables </li>
<li> Fruit </li>
<li> Flowers </li>
<li> Drinks </li>
</ul>
</body>

UI element State pseudo class selector
in a Web page, a UI element typically refers to a form element that is contained within a FORM element.
Common State Pseudo-class selectors
Selector Description
e:enabled selects all available UI elements that match E, matching <input type= "text" >
e:disabled Select all the unavailable UI elements that match E, matching <input type= "button" disabled= "Disabled" >
e:checked selects all available UI elements that match E, matches <input type= "checkbox" checked= "Checked" >
Example:
<! DOCTYPE html>


<title></title>
<style>
input:enabled{
border:1px dotted #666; background: #ff9900;
}
input:disabled{
border:1px dotted #999; background: #f2f2f2;
}
</style>

<body>
<div style= "Text-align:center" >

<form method= "POST" action= "" >
<p>username: <input type= "text" name= "username" ></p>
<p>password: <input type= "password" name= " passwd" disabled= "disabled" ></p>
<p>
<input type= "Submit" value= "Submit" >
<input type= "reset" value= "reset" >
</p>
</form>
</div>
</body>

Study 5--CSS Overview

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.