Width"Shrinkage" and "extension" adaptation of attributes
AllWidthEach attribute element has a defaultAutoValue, but in useAutoNot all elements have the same effect. For example, <Table>The element only scales horizontally to accommodate the data in it. This method is called "contraction adaptation ". On the other hand,<Div>This method is called "Scaling adaptation ".
Computing selector targeting
As a supplement to the style table priority, the selector in each style table also has a priority order. This priority is determined by the selector's pertinence. For example, IDSelector is the most targeted and general selector is the most general. Between them, the selector uses the following formula for calculation:
1,Set a variableA,If the style is(X) HTMLOfStyleAttribute application,AIs1Otherwise0.
2,Calculating SelectorIDNumber of attributes, and sum of VariablesB.
3,Calculates the number of attributes, pseudo classes, and class names in the selector. The sum of the three is a variable.C.
4,Calculates the number of element names in the selector, and is a variable.D.
5,Ignore pseudo elements
.Connect the numbers in each variable to obtain the selector's pertinence. Connection is a programming term that indicates bonding. HereA,B,C,DConnection resultABCDInstead of ComputingA,B,C,DAnd get another variable.E.
Selector |
Selector type |
Targeted |
* |
General Selector |
0000 (A = 0, B = 0, c = 0, D = 0) |
Li |
Element name |
0001 (A = 0, B = 0, c = 0, D = 1) |
Ul Li |
Element name |
0002 (A = 0, B = 0, c = 0, D = 2) |
Div H1 + P |
Element name |
0003 (A = 0, B = 0, c = 0, D = 3) |
Input [type = 'text'] |
Element name+Attribute |
0011 (A = 0, B = 0, c = 1, D = 1) |
. Someclass |
Class Name |
0010 (A = 0, B = 0, c = 1, D = 0) |
Div. someclass |
Element name+Class Name |
0011 (A = 0, B = 0, c = 1, D = 1) |
Div. someclass. someother |
Element name+Class Name+Class Name |
0021 (A = 0, B = 0, c = 2, D = 1) |
# Someid |
IDName |
0100 (A = 0, B = 1, C = 0, D = 0) |
Div # someid |
Element name+ IdName |
0101 (A = 0, B = 1, C = 0, D = 1) |
Style (Attribute) |
Style (Attribute) |
1000 (A = 1, B = 0, c = 0, D = 0) |
Targeted charts include0To indicate how the connection works, but it must be omitted. To determine the priority, you only need to determine the maximum number. When two or more selectors have the same priority, the last one applies first.StyleProperty takes precedence over all other rules.
!ImportantRules
WithCSSThe cascade mechanism in comes with the need to rewrite it. That's it!ImportantRule source .!ImportantSyntax appears in the declaration, after the attribute value, before the semi-colon. The syntax consists of two parts: an exclamation mark as the separator, and thenImportant
Keyword. The delimiter indicates the end of one component and the start of the other. Here, the exclamation mark marks the end of the statement.ImportantThe keyword must appear immediately, followed by a semicolon that ends the entire declaration.
For example:
P {
Background: lightblue! Important;
}
This rule takes precedence overStyleAttribute.
UseMarginAttribute to horizontally align Elements
UseAtuoKeyword andMarginAttribute collaboration can align left, center, or right.
Left alignedMargin-leftSet0, margin-RightSetAuto, Right alignment, and vice versa.Auto.
HoweverIE (Different from standard)AvailableText-alignAttribute to align elements. This technology does not work in other browsers.
Width and heightAutoValue
By default,WidthAndHeightThe property value isAutoSo when the width and height are not specified, their values areAutoKeyword.AutoThe keyword is changed based on the element type of the application. When it is applied in<Div>When the element is on, it means that the element will span across all available controls; vertically, it will expand to accommodate all content inside the element, including text, images, or other boxes. Elements with such behavior are called block-level elements.<Div>,<P>,<H1> ~ <H6>,<Form>And<Ul>Elements.
Floating Box Model
Floating elements are repositioned to allow other contents to float around them. This behavior is unique. This behavior is described as follows:
1,The margins of floating elements are not folded, no matter how close they are
2,Only the element content after the floating element is affected by the floating element. That is to say, the background, outer border, border, inner margin, and width of the element behind the floating Element(Box Model and size)Are not affected.
3,Floating elements are always treated as block-level elements.
When an element floats, it acts like a block-level element, but there is a major difference: its size is changed to horizontal direction and vertical direction are adaptive to shrinkage. This means that<Div>When an element is used, its size will only be extended enough to accommodate the content.
Relative positioning:
1,Relative positioning is similar to static positioning, and its elements are kept in Zhengcai's document stream, but this is only a similarity.
2,Relative positioning elements can be used as reference points for absolute positioning elements.
3,Acceptable relative positioning Elements4Offset attributes can be combined in the following ways:TopAndLeft,TopAndRight,BottomAndLeft,BottomAndRight, The browser will ignore other combinations. For example, you cannot useTopAndBottomOffset property.
4,Relatively positioned content can be stacked and placed in layersZAxis