CSS Learning notes One

Source: Internet
Author: User

CSS Learning Note 1


1. Select a selector for a specific element:

      • Context Selector

Label 1 label 2 {declaration}
Where label 2 is the target to select, it is selected only if label 1 is its ancestor (not necessarily the parent element).
CSS code:

Body Code:

Understanding : The section label article tag is a contextual relationship, that is, article is a descendant of section, only the style of the section is applied to apply the article style.
Note : The space problem in the inheritance relationship, there is a space for the relationship between ancestor and descendant, CSS notation, body code for, Description page style table file according to the page elements from the inside to outside of the order to read;
There is no space between the two, is this way of writing, the body code is:, the description of the style sheet is not a space for the current element is determined, indicating that there is a intersection.

      • Special Contextual Selectors >

Label 1> label 2 {declaration}
Label 2 must be a child of label 1, that is, label 1 must be the parent element of label 2.
CSS code:

Body Code:
CSS can be located in the UL style, but not to the Li, because they are ancestral relationship, not a simple parent-child relationship.

      • Close to sibling selector +

Label 1+ label 2 {declaration}
Label 2 must be immediately behind its fellow label 1.
CSS code:
Body Code:
:
This effect is generally used in navigation and can be understood as "non-first child element selectors".

      • Universal Selector *

* is a wildcard character that can match any element. In CSS, we may often see this code *{margin:0;padding:0;} It does this: the browser has its own default value for the tag, and if marked with a *, it will eliminate the default internal and external margins of the browser.

      • Property name Selector

Label name "property name" {declaration}
Select any label with a property name.
CSS code and:

Select the "submit" setting style in the type attribute of input.

2.ID and Class selectors:
By adding an ID and class attribute to an element in an HTML tag, you can use the ID and name in the CSS selector to set any value for the ID and Class attribute values, but not to start with a number or a special symbol.

3. When do I use classes and IDs?
With the uniqueness of the ID, you can easily navigate to this element in CSS, and its child elements, there is a certain degree of rule to add an ID to each top-level area of the page, so that a very clear context, so that when writing CSS can only choose to nest in the corresponding area of the label.
The purpose of the class is to identify a set of elements that have the same characteristics.

4.UI pseudo-Class

      • Link pseudo-class:link. At this point, the link is waiting for the user to click.

Visited. The user has previously clicked on this link.
Hover The mouse pointer is hovering over the link.
Active The link is being clicked (the mouse is pressed on the element and has not been released)
Mouse hover to change color:

      • : Focus Pseudo-Class (E:focus,e represents any element)

The text field of the form gets the focus when the user taps it, and then the user can enter characters in it. Like what:
Adds a blue border to the field when the cursor is in the input field.

5. Structured pseudo-Class
E:first-child and E:last-child,: First-child represents the first element in the same group of siblings, and Last-child represents the last of the same group of compatriots.


The last list item has a border that does not appear
: Nth-child e:nth-child (n) : n denotes a numeric value (can also use odd or even parity)
The most common use is to improve the readability of the table, such as applying different colors to all rows of the table alternately.

6. Pseudo-Elements

      • :: First-letter,::last-letter;

To achieve the first character sinking effect: (If you do not create this first character amplification effect with pseudo-elements, you must manually add <span> tags to the alphabet, and then apply the style in place of the tag) and the pseudo-element actually adds an invisible label for us.

      • :: First-line


Use:: The first-line pseudo-element turns the first line into a small capital letter, and changes the length of the element as the size of the browser window changes.

      • :: Before with:: After

Can be used to add special content before or after a specific element. (such as adding triangles when the popup layer is set)
The Content property value has spaces in order to output the appropriate distance in the result.

7. Inheritance : The ancestor elements in CSS will pass the values of CSS properties to descendants, many inheritable attributes are related to text, such as color, font, size, and many can not be inherited, these elements mainly related to the element box positioning and display methods, such as border, margin, padding.

8. Cascading : Cascading style sheets, is a style in the text hierarchy layer by level overlay process, the purpose is to let the browser face a particular tag specific properties worth multiple sources, determine the final use of that value.

      • Browser cascade The order of each source style:
      • browser default style sheet;
      • User style sheet;
      • Author link style sheets (in the order they are linked to the page)
      • Author embedding style;
      • Author in-line style.
      • Cascading rules:

Rule one: find all claims that are applied to each element and attribute.
rule two : Sort by order and weight. Spaces The important semicolon is used to weigh the weight of the declaration, such as: (P{color:green!imporant;} Heavier weights that set text to green. )
Rule three : Sort by specified degree.
calculation specificity: Scoring rules i-c-e

      1. There is an ID in the selector, which adds 1 to the position of I;
      2. There is a class in the selector that adds 1 to the position of C;
      3. There is an element (label) name in the selector, plus 1 on the position of E;
      4. Get a three-digit number to compare.

note that ice is not really a three-digit number, but in most cases the result is seen as a three-digit number with no problem, and the three-digit maximum wins. But it must be known that 0-1-12 and 0-2-0 are still more 0-2-0 than the special system.

Rule Four : The order determines the weights.
Simple CASCADE Requirements:

Rule one: a selector that contains an ID is more than a selector that contains a class, and a selector that contains a class trumps a selector that contains a tag name.
Rule Two : if several different sources define styles for the same attribute of the same label, inline is better than embedded, and inline is better than link style. In a linked style sheet, a style that has the same special system, which is declared better than the first declaration.
Rule Three : The style is better than the inheritance style, this time does not consider the special system (that is, explicit set precedence).

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.