CSS document flow and block-level elements (block) and inline elements (inline). I have read many books and read many articles before. All I have seen is fragmentary basic knowledge of CSS layout, which is relatively superficial. I have read O' Reilly's "The Definitive Guide to CSS", I found that the concept of document flow mentioned in it made me very sensitive. Unfortunately, the book did not explain what document flow is. Maybe the author thought it was too simple to be worth mentioning. But I think this concept is really important. After understanding it, a bunch of CSS layout theories become easy to understand, and I realize the rationality of CSS design. So based on my guesses and experiments, I came up with this Statement. If there are any errors, it is completely normal.
Document flow divides the form into rows from top to bottom, and arranges the elements in each row from left to right, which is the document flow.
Each non-floating block-level element occupies its own line, and floating elements float at one end of the line as required. If the current line cannot fit, it will be floated on a new line.
Inline elements will not occupy a row. Almost all elements (including block-level, inline and list elements) can generate sub-rows for placing sub-elements.
There are three situations that will cause elements to exist out of the document flow, namely floating, absolute positioning, and fixed positioning. But in IE, floating elements also exist in the document flow (which makes me think this is reasonable><).
Floated elements do not occupy any normal document flow space, and the positioning of floating elements is still based on the normal document flow, and then extracted from the document flow and moved as far as possible to the left or right. The text content will be wrapped around the floated element. When an element is extracted from the normal document flow, other elements still in the document flow ignore the element and fill its original space.
The confusing concept of floating is caused by the browser's interpretation of the theory. It can only be said that many people use IE as the standard, but in fact it is not.
Based on document flow, we can easily understand the following positioning patterns:
Relative positioning, that is, offset relative to the position of the element in the document flow. But retain the original placeholder.
Absolute positioning, that is, completely out of the document flow, offset and fixed positioning relative to the nearest parent element with a non-static value of the position attribute. Absolute positioning, that is, completely out of the document flow, offset relative to the viewport.
There are still a few questions I have to deal with. I don’t understand
1. As one of the three basic elements, what is the main difference between inline elements and block-level elements?
2. How do you understand when the Clear attribute takes the right value? It seems that the experimental situation is always inconsistent with the theory.
What does the inline element mean? What are block level elements.
"CSS Definitive Guide" Chinese text shows: Any visible element that is not a block-level element is an inline element. The characteristic of its performance is the form of "row layout". The "row layout" here means that its form of expression is always displayed in rows. For example, when we set an inline element border-bottom:1px solid #000;, it will be repeated in each row, and there will be a thin black line below each row. If it is a block-level element, the black line displayed will only appear below the block.
Elements such as p, h1, or div are often called block-level elements, and these elements are displayed as a block of content; elements such as Strong and span are called inline elements, and their content is displayed in the line, that is, "inline box". (You can use display=block to convert inline elements into block elements. display=none means that the generated element has no frame at all, neither displays the element nor takes up space in the document)
A: Inline elements are elements within a row and can only be placed within a line; block-level elements are just a four-square box and can be placed anywhere on the page.
B: To put it bluntly, an inline element is like a word; a block-level element is like a paragraph. If it is not otherwise defined, it will appear on its own line.
C: General block-level elements such as paragraph <p>, title <h1><h2>..., list, <ul><ol><li>, table <table>, form <form>, DIV<div> and BODY <body> and other elements. Inline elements are such as: form elements <input>, hyperlinks <a>, images <img>, <span>…..
D: The notable feature of block-level elements is that each block-level element starts displaying on a new line, and subsequent elements also need to be displayed on a new line.
E: <span> is an inline element in the CSS definition, while <div> is a block-level element.
For those who have learned CSS, they can understand it immediately. But it is not easy for novices to understand, so I mainly want to make it more familiar to novices!
Using the word container will make it easier to visually understand their existence and purpose. Inline elements are equivalent to small containers, while <div> is equivalent to a large container. Of course, a small container can be placed in a large container. <span>It is a small container. This way you may have a preliminary impression in your mind. If we want to put some water in a large container. But what if I also want to put some ink in it? It's very simple. We take out the small container, fill it with ink and put it into the clean water in the large container.
Let me give you a simple practical example: for example <div>I love CSS - 52CSS.com</div>
I want to style the letter c using CSS, so we can use <span>.
<div>I love CSS - <span>52CSS.com</span> W3C Standard</div>
A block element is generally a container element for other elements. Block elements generally start on a new line. It can accommodate inline elements and other block elements. A common block element is the paragraph tag 'P". The "form" block element is quite special. , it can only be used to hold other block elements.
Without the help of CSS, block elements will be arranged one row at a time. With CSS, we can change the default layout mode of this HTML and place the block elements where you want. Instead of stupidly starting a new line every time. It should be pointed out that the table tag is also a type of block element. Table based layout and css based layout look at these two layouts from the perspective of ordinary users (excluding visually impaired people, blind people, etc.), except for page loading speed. Except for the difference, there is no other difference. However, if an ordinary user inadvertently clicks the view page source code button, the difference between the two will be very large. The CSS layout page source code designed based on good reconstruction concepts can at least allow ordinary users without web development experience to quickly understand the content. From this perspective, css layout code should have a better aesthetic experience.
You can think of the block container element div as boxes, or if you have played with clipping, it will be easier to understand. We first cut out the necessary articles from various newspapers and magazines. Each piece of cut content is a block. Then we glued these pieces of paper onto a new piece of blank paper according to our layout intention. This will form your own unique abstract. As an extension of the technology, web layout design follows the same pattern. .Inline
elements are generally based on basic elements at the semantic level. Inline elements can only hold text or other inline elements, and the common inline element "a" is.
Block element (block element) and inline element (inline element) are concepts in the HTML specification. The basic difference between block elements and inline elements is that block elements generally start on a new line. When CSS control is added, this attribute difference between block elements and inline elements no longer becomes a difference. For example, we can add an attribute such as display:block to the inline element cite, so that it also has the attribute of starting from a new line every time.
The basic concept of a mutable element is that it needs to determine whether the element is a block element or an inline element based on the context. Variable elements still belong to the above two element categories. Once the context determines its category, it must follow the rules of block elements or inline elements. See full text for rough element classification.
Regarding the Chinese name of inline element, there are many kinds of inline elements, inline elements, inline elements, and inline elements. Basically there is no unified translation, just call it whatever you want. In addition, when talking about inline elements, we will think of a display attribute called display:inline; this attribute can fix the famous IE double floating border problem.
block element
* address - address * blockquote - block reference * center - alignment block * dir - directory list * div - commonly used block level, also the main label of CSS layout * dl - definition list * fieldset - form control group * form - interaction Form* h1 - Heading * h2 - Subtitle * h3 - Level 3 heading * h4 - Level 4 heading * h5 - Level 5 heading * h6 - Level 6 heading * hr - Horizontal dividing line * isindex - input prompt
* menu - menu list * noframes - frames optional content, (this block content is displayed for browsers that do not support frames) * noscript - optional script content (this content is displayed for browsers that do not support script)
* ol - sorted form * p - paragraph * pre - formatted text * table - table * ul - non-sorted list
inline element (inline element)
* a - anchor point * abbr - abbreviation * acronym - first word * b - bold (not recommended)
* bdo - bidi override
* big - large font * br - line break * cite - quote * code - computer code (required when citing source code)
* dfn - define fields * em - emphasize * font - font settings (not recommended)
* i - italic * img - picture * input - input box * kbd - define keyboard text * label - table label * q - short quote * s - underline (not recommended)
* samp - defines sample computer code * select - item selection * small - small font text * span - commonly used inline container, defines blocks within text * strike - underline * strong - bold emphasis * sub - subscript * sup - Superscript * textarea - Multi-line text input box * tt - Teletype text * u - Underline * var - Define variables
Variable elements Variable elements determine whether the element is a block element or an inline element according to the context.
* applet - java applet
* button - button * del - delete text * iframe - inline frame
* ins - inserted text * map - image block (map)
* object - object object * script - client script