CSS Learning notes One

Source: Internet
Author: User

CSS Full name: Cascading style sheet (cascading style Sheets), used to define the display of the page, you can resolve the HTML code overlap style definitions, improve the maintainability of the late style code, and enhance the display of the Web page.

Summary: CSS separates the content and style of the Web page (that is, reduced coupling in Java, thereby increasing extensibility) and improving the display functionality.

HTML to improve enough tags to encapsulate, improve a lot of results, but the effect is limited, so the effect of a separate language CSS, to solve the problem of the page effect


One, there are four ways in which HTML and CSS are combined:


1,style Property mode

2,style label mode (inline mode)

3, Import mode

4, Link way

First Kind

<!--1,style Property Way: The property value is CSS code       --<div style= "background-color: #06F; color: #F00" >                This is the div1 of CSS       </div>


The second Kind

The Div area becomes the same style, but in order to simplify the code, the second way

  <!--2, using the Style tab--    <style type= "text/css" >//Declaration, CSS style        div{<span style= "White-space:pre" ></span>//Declaration is div area            background-color: #000;            Color: #FFF        }    </style>//generally in 
Because you want to open the Web page is effective, so first loaded, placed in the

PS: When encountering a new div style, will overwrite, this is the style of cascading, such as 9 div area like the same style, 1 different, then the 10 div style will be placed in the same

Third Kind

How to write CSS to a file, HTML import

A webpage can use the above way, but 10, can not each webpage, add <style>, so will Div{background-color: #00F;
Color: #0F3;} Encapsulate a div.css file, and then use the @import url ("Div.css") in the html<style>, import it, if the. css file is many, then you can @import url ("Div.css"); Wait for the file to import another 1. CSS file, then import 1.css in HTML

@import url ("Div.css");  @import URL in 1.css file ("Span.css");


div{           //div.css file    background-color: #00F;    Color: #0F3;}

Recommend each kind of samplestyle effects are written separately in a file, and the CSS annotations are/**/


Fourth type



Two, style priority

From top to bottom, from outside to inside, priority from low to high, generally, post-loaded, mainly


Third, CSS syntax structure

Selector Name {property Name: property value; Property Name: property value;...}

Semicolon split between property and property

property is concatenated with the property value with a colon

If one property, multiple values, values are separated by a space



Four, selector

is to specify the CSS to function the label, the name of the tag is the selector, meaning: Choose which container

There are three kinds of selectors:

1,html Tag Selector, using the tag name of HTML:

The 2,class selector, in fact, uses the class attribute in the tag

3,id selector, using the id attribute in the tag

Each tag is defined with a class attribute and an id attribute, which is used to identify the label and facilitate the operation of the label.

The class property values for multiple tags can be the same, but the id attribute values are unique, and JavaScript often uses


HTML tag name selector, previously used

Class selector:

Multiple tags, all with the same attribute, then you can use: (. Name) to define


Predefined styles, such as the one above, and then A. nihao{...}, click the button page style to change the Nihao defined effect, which allows for dynamic loading


ID selector:

There is no difference between the usage and the class selector, but the value of the ID is unique in the page and is used by JavaScript in addition to the CSS.

Multiple styles are sufficient to use class, but IDs are often used to identify specific areas of the page

Above three priority levels: Tag Selector < class selector <id selector <style Property


Five, correlation selector and combo Selector

Association selector format: Tag name + space + label signature


Combo Selector

Selector name + comma + selector name


CSS Learning notes One

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.