


In-depth understanding of CSS/block-level elements and inline elements_html/css_WEB-ITnose
Today I finally have a more rational understanding of block-level elements and inline elements in HTML. First of all, w3c’s explanation of block and inline is:
1. Research on block
Through w3c’s explanation, that is to say, block (block Level) elements are displayed on their own line. Its sibling elements must not be on the same line as it (unless out of the document flow). Let’s talk about the default width of block elements.
1. No width is set: the default is the same width as the browser's viewable area (after the browser's default style is reset).
The yellow line you see is actually a DIV with no width and height set. The border is a 1-pixel solid yellow line. It can be seen that it covers the entire screen.
2. The width is not set, but the width is set by the parent element:
In this example, the yellow line is a P with no width set, and its parent element is A DIV with a width of 200px, the offsetWidth (offsetWidth=border width padding) attribute of P output in the console is: 200. In other words, P inherits the width of DIV to a certain extent. But it’s not entirely true, because the width of the printed P is added with the border width of 2px, so if the width of the child element is not set, it will fill 100% of the width of the parent element, but it will not fill the height. !
Look at the following example question:
Already have HTML code:
If the following CSS is applied:
.a{ width:200px; height:100px;}
.b{ padding:20%; background -color:red; } What is the size of the red area? width? height?
Analysis, because .b is a child element of .a, and .b has no width set, we know from the research just now that the width of .b completely fills .a, This width includes the border and padding. In other words, the width of the .b we can see is still 200px, and will not be enlarged due to the addition of padding ! The height is not the case, it is 200*20%*2=80px.
So the answer to this question is readily apparent: width: 200px; height: 80px. (But the situation under ie6 and mixed mode has not been tested)
2. Research on inline
Inline elements can be displayed on the same line Multiple lines will not be wrapped until the browser window is not wide enough to accommodate them. Let's take a look at the width and height of inline elements.
1. A span element with no width and height set, and a 1-pixel blue solid line is added to the display effect to be purple:
2. After adding a height of 50px to his father It’s purple:
There is no change between 1 and 2.
3. After adding a height of 50px, it will be purple:
1, 2, and 3 display exactly the same. .
Normal document flow inline does not support width and height settings, so the span in the example will not inherit the width and height of its father, and the width and height set by yourself will not work. The height itself is actually the default line-height height value. Let’s take a look at adding padding to it:
This is the case where padding: 10 is added. His father I set a DIV with a height of 10px. It can be seen that span exceeds the DIV, so the width and height of the inline element have nothing to do with the parent element.
3. Summary of the difference between inline and block
1. The intuitive difference between inline elements and block-level elements
Inline elements will be arranged in a straight line, all on the same line, arranged horizontally
Block-level elements each occupy one line, arranged vertically. Block-level elements start on a new line and end with a line break.
2. Block-level elements can contain inline elements and block-level elements. Inline elements cannot contain block-level elements.
3. The difference in attributes between inline elements and block-level elements is mainly in the box model attributes. Setting width for inline elements is invalid, height is invalid (line-height can be set), margin top and bottom are invalid, and padding is invalid.
4. Common inline elements and block elements

HTML, CSS and JavaScript are the core technologies for building modern web pages: 1. HTML defines the web page structure, 2. CSS is responsible for the appearance of the web page, 3. JavaScript provides web page dynamics and interactivity, and they work together to create a website with a good user experience.

The function of HTML is to define the structure and content of a web page, and its purpose is to provide a standardized way to display information. 1) HTML organizes various parts of the web page through tags and attributes, such as titles and paragraphs. 2) It supports the separation of content and performance and improves maintenance efficiency. 3) HTML is extensible, allowing custom tags to enhance SEO.

The future trends of HTML are semantics and web components, the future trends of CSS are CSS-in-JS and CSSHoudini, and the future trends of JavaScript are WebAssembly and Serverless. 1. HTML semantics improve accessibility and SEO effects, and Web components improve development efficiency, but attention should be paid to browser compatibility. 2. CSS-in-JS enhances style management flexibility but may increase file size. CSSHoudini allows direct operation of CSS rendering. 3.WebAssembly optimizes browser application performance but has a steep learning curve, and Serverless simplifies development but requires optimization of cold start problems.

The roles of HTML, CSS and JavaScript in web development are: 1. HTML defines the web page structure, 2. CSS controls the web page style, and 3. JavaScript adds dynamic behavior. Together, they build the framework, aesthetics and interactivity of modern websites.

The future of HTML is full of infinite possibilities. 1) New features and standards will include more semantic tags and the popularity of WebComponents. 2) The web design trend will continue to develop towards responsive and accessible design. 3) Performance optimization will improve the user experience through responsive image loading and lazy loading technologies.

The roles of HTML, CSS and JavaScript in web development are: HTML is responsible for content structure, CSS is responsible for style, and JavaScript is responsible for dynamic behavior. 1. HTML defines the web page structure and content through tags to ensure semantics. 2. CSS controls the web page style through selectors and attributes to make it beautiful and easy to read. 3. JavaScript controls web page behavior through scripts to achieve dynamic and interactive functions.

HTMLisnotaprogramminglanguage;itisamarkuplanguage.1)HTMLstructuresandformatswebcontentusingtags.2)ItworkswithCSSforstylingandJavaScriptforinteractivity,enhancingwebdevelopment.

HTML is the cornerstone of building web page structure. 1. HTML defines the content structure and semantics, and uses, etc. tags. 2. Provide semantic markers, such as, etc., to improve SEO effect. 3. To realize user interaction through tags, pay attention to form verification. 4. Use advanced elements such as, combined with JavaScript to achieve dynamic effects. 5. Common errors include unclosed labels and unquoted attribute values, and verification tools are required. 6. Optimization strategies include reducing HTTP requests, compressing HTML, using semantic tags, etc.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Notepad++7.3.1
Easy-to-use and free code editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.