div is used to group block-level elements, and span is used to group row-level elements. div stands for division, which can separate the document into several meaningful parts. div should only be used when no existing elements can achieve area separation.
There are no corresponding elements in HTML, making it difficult to highlight information such as people, places, dates, etc.
Reference: Microformat
DTD is a set of machine-readable rules that define what is allowed and what is not allowed in a specific version of XML or HTML. When parsing a web page, the browser will Use these rules to check the validity of the page and take appropriate actions
Browser manufacturers began to create standards-compliant browsers, they wanted to ensure backward compatibility, they created
: hover: active and: focus are called dynamic pseudo-classes, which can theoretically be used for any element
Universal selector: *, which can be used to apply styles to all descendants of an element, or skip one level of descendants
The author's style sheet, i.e. the site developer, is the most important, followed by the user, and finally the default style sheet used by the browser or user agent
If the specificity of the two rules is the same, then the last definition The priority
cascade adopts the following order of importance:
is marked with! important user style
Any style applied directly to an element will always override the inherited style because the inherited style specificity is null
Planning for Organizing and Maintaining Stylesheets: Ways to Manage Your Code
Multiple files can cause problems from The server sends more packets and the number of these packets (not the content) affects the download time
Browsers can only download a limited number of files from the same domain at the same time (2 for old browsers, 2 for modern 8 browsers)
CSS uses c-style /* */ comments. It is recommended to add a flag @ comment in each comment header to facilitate search
Link: CSSDoc Project: CSS Module Annotations
CSS document structure
------------------ -------------------------------------------------- -*/
Body style
--------------------------------- ------------------------------------*/
Forms
----- -------------------------------------------------- ---------------*/
Header, footer and navigation
----------------------- --------------------------------------------------*/
Each page
------------- -------------------------------------------------- -----*/
Color reference value table
/* Color Variables
@colordef #434343; dark gray;
@………………………………………….
*/
CSS Optimization
Link:
Server-side compression: Apache’s mod_gzip or mod_deflate
If you add a background on an element, the background is applied to an area consisting of content and padding, so we often use padding to create an isolation band around the element, making the content It will not be mixed with the background. Adding a border will add a line outside the inner margin. Outside the border is the outer margin. The outer margin is transparent. It is generally used to control the spacing between elements.
css2.1 also includes the outline attribute, unlike the border attribute, outlines are drawn above the element box, so they do not affect the size and positioning of the element, so outline helps fix bugs because they do not affect the page layout, most modern browsers (including IE8) support outlines.
Padding, borders, and margins are all optional and default to 0. But many elements will have margins and padding set by user-agent stylesheets.
Margins can be negative
Margin stacking: when two or more vertical margins meet, they will form a margin with a height equal to two The larger of the heights of the margins at which overlapping occurs. When an element is contained within another element, their top and bottom margins will also overlap, assuming there is no padding or border separating them. If an empty element only has margins but no padding and borders, its own top and bottom margins will also overlap.
Margin overlay actually has important meaning, it makes the distance everywhere on the text page consisting of several paragraphs consistent.
Only the vertical margins of block boxes in ordinary documents will overlap. The margins between inline boxes, floating boxes or absolutely positioned boxes will not overlap.
display: change the type of generated box
The horizontal box formed by a line is called a line box. The height of the line box is always enough to accommodate all the inline boxes it contains, but setting the line height can increase the height of this box, so modify the size of the inline box. The only way is to change the line height or horizontal border padding and margins.
Understand that everything seen on the screen forms some kind of box
It is not possible to apply styles directly to anonymous blocks or line boxes, except by using the less common: first-line pseudo-element
Relative positioning: position: relative;
Relative positioning is actually considered part of the normal flow positioning model, because the position of an element is relative to its position in the normal flow The initial position is offset, but regardless of whether it is moved or not, the element still occupies the original space, so moving the element will cause it to cover other boxes.
A floating box can be moved left or right until its outer edge touches the edge of the containing box or another floating box. Because the floating box is not in the ordinary document flow, the block box in the ordinary document flow behaves as if the floating box does not exist
In fact, the floating box does not affect the non-floating elements at all. If the floating box If there is an element in the document flow behind the element, then the box of this element will behave as if the float does not exist at all. However, the text content of the box will be affected by the floating element and will move to leave space. In technical terms, the line box next to the floated element is shortened to make room for the floated element, so the line box wraps around the floated box (floats are actually designed to achieve a text wrapping effect).
To prevent line boxes from surrounding the outside of the floating box, you need to apply the clear attribute to the elements containing these line boxes. The value of the clear attribute can be left, right, both, and none, which represents which parts of the box The edges should not be next to the floated box. When clearing an element, the browser adds enough margin to the top of the element so that the top edge of the element drops vertically below the floated box.
A floated element breaks out of the document flow and does not affect surrounding elements, but cleaning the element actually leaves vertical space for the floated element in front of it.
Absolute positioning makes the position of the element independent of the document flow. It does not occupy space. The layout of other elements in the ordinary document flow is as if the absolutely positioned element does not exist. . If an absolutely positioned box is enlarged (e.g. by increasing the font size) the surrounding boxes will not be repositioned, so any change in size has the potential to cause the absolutely positioned boxes to overlap, ruining a carefully tuned layout
An absolutely positioned element is positioned relative to its nearest positioned ancestor, or, if none exists, relative to the initial containing block.
Because absolutely positioned boxes have nothing to do with document flow, they can cover other elements on the page. The stacking order of these boxes can be controlled through the z-index attribute. The higher the z-index value, the better the frame is. The higher the position in the stack.
Fixed positioning: position: fixed;
Fixed positioning is a type of absolute positioning. The difference is that the containing block of the fixed element is the browser window (viewport), which allows us to create an overall Is a floating element that appears in the same position in the window
Earlier versions of IE, including IE6, use their own non-standard box model in promiscuous mode, and the width attribute of these browsers Not the width of the content, but the sum of the widths of the content, padding and borders. So IE's proprietary box model makes elements smaller than expected.
IE6 does not support fixed positioning, IE7 partially supports it, and has many bugs