CSS syntax

xiaoxiao2021-03-06  93

OF: Unknown Source: 1. Display 5D CSS syntax is defined substantially composed of three parts: selectors (selector), attributes (Properties) and value attribute (value). The basic format is as follows: selector {property: value} (Select {Property: Valid}) Selector can be in a variety of forms, usually you want to define the HTML tag, such as Body, P, Table ... you can pass This method defines its properties and values, attributes and values ​​to be separated by colon: body {color: black} selectors Body refers to the page body part, and color is the property of the control text color, the Black is the value of the color, this example The effect is that the text in the page is black. If the value of the attribute is a plurality of words, you must add quotes on the value. For example, the name of the font is often a combination of words: p {font-family: "Sans Serif"} (defined paragraph fonts for Sans Serif) if needed When multiple properties are specified for a selector, we use the semicolon to open all the properties and values: P {text-align: center; color: red} (paragraph hide in the paragraph; the text in the paragraph is red) In order to make you The defined style sheet is convenient to read, you can use branch writing format: p {text-align: center; color: black; font-family: arial} (paragraph arrangement, paragraph Chinese is black, font is arial) 2. The selector group you can combine the selectors of the same properties and values, separated by a comma, which can reduce style repeat definition: H1, H2, H3, H4, H5, H6 {color: Green} (this group) Includes all the title elements, each title element is green) P, table {font-size: 9pt} (paragraph and table size in the form) effect is completely equivalent to: p {font- Size: 9pt} Table {font-size: 9pt} 3. Class selection class selector You can define different styles to define different styles, define a class selector, add a point in front of the custom class. . If you want two different paragraphs, a paragraph is aligned, a paragraph is fell, you can define two classes: p.right {text-align: right} P.Center {text-align: center} then Not in different paragraphs, as long as you join your defined class parameters in the HTML tag:

This paragraph is right-oriented

This paragraph is in place. Note: The name of the class can be any English word or a combination of the beginning and the number in English, which is generally nimed in its function and effect.

The class selector has an usage, omitting the HTML tagname in the selector, which can define several different elements to be the same style: .Center {text-align: center} (definition .center class selector is text Critical arrangement) This class can be applied to any element. Below we make H1 elements (title 1) and P element (paragraphs) are classified as "center" class, which makes the pattern of two elements ".center" selectors:

this The title is the

that is in place: this omitted HTML tag class selector is the most commonly used CSS method after we are using this. Method, we can easily use pre-defined class patterns on any elements. 4. ID Select The ID parameter in the HTML page specifies a single element, and the ID selector is used to define a separate style for this single element. The application of the ID selector is similar to the class selector, as long as the Class is replaced with an ID. In the case of the class with the class:

This paragraph to right to the right definition ID selector to add a "#" number before the ID name. There are two ways to define the attributes of the ID selector. The following example, the ID attribute will match all ID = "INTRO" elements: #inTro {font-size: 110%; font-weight: bold; color: # 0000ff; Background-color: Transparent} (font size is default size 110%; bold; blue; background color transparent) Below this example, ID attribute only matches ID = "INTRO" paragraph element: P # INTRO {font-size: 110%; font-weight: bold; color: # 0000FF; Background-Color: Transparent} Note: The ID selector is limited, only the style of an element can only be defined, usually only in special cases. 5. Contains the selector to include a style sheet defined by a relationship to a certain element, and an element 1 contains element 2, which is only defined on the element 2 in element 1, and is unfained to individual elements 1 or element 2. For example: Table a {font-size: 12px} The link in the table changes the style, the text size is 12 pixels, and the text of the table is still the default size. 6. The stacked laminated stack of style sheets is inheritance, and the inheritance rules of the style sheet are external element patterns to keep other elements contained in this element. In fact, all elements nested in the elements will inherit the attribute values ​​specified in the outer element, and sometimes many layers of nesting styles are superimposed together unless otherwise change. For example, nested in the DIV mark: div {color: red; font-size: 9pt} ...

This paragraph text is red 9 word (P element The content of the content will inherit the attribute defined by the DIV) Note: Some cases do not inherit the value of the surrounding selectors, but these are special.

转载请注明原文地址:https://www.9cbs.com/read-96562.html

New Post(0)