Display is officially defined as: Specifies the type of box that the element should generate. This article only focuses on the six commonly used values: none, block, inline, inline-block, inherit, and flex. Other tables, list-items, etc. are no longer recommended.
一、None
This element will not be displayed. It is mainly distinguished from when the visibility attribute is hidden.
1) When the element is none, js can get this element, but it cannot get/set the value of the visual attribute of this element (but it can set the value of custom attribute), such as the value of CSS attributes such as Width, Height, background, etc. This also means that when the element is none, the element is not rendered by the browser.
2) When the visibility value of an element is hidden, although the element is invisible, you can get/set any value of the element, including CSS-related attributes. This also indicates that the element at this time is rendered by the browser (it occupies a position in the document flow), but is in an invisible state.
3) The sample code is as follows:
Css code:
<span style="color: #800000;">#div01</span>{<span style="color: #ff0000;"> display</span>:<span style="color: #0000ff;"> none</span>;<span style="color: #ff0000;"> width</span>:<span style="color: #0000ff;"> 200px</span>;<span style="color: #ff0000;"> background</span>:<span style="color: #0000ff;"> red</span>; }<span style="color: #800000;"> #div02</span>{<span style="color: #ff0000;"> visibility</span>:<span style="color: #0000ff;"> hidden</span>;<span style="color: #ff0000;"> width</span>:<span style="color: #0000ff;"> 100px</span>; }<span style="color: #800000;"> #div03</span>{<span style="color: #ff0000;"> width</span>:<span style="color: #0000ff;"> 100px</span>; }
Js/html code:
<div id="div01" data-name="div01"> div01</div> <div id="div02" data-name="div02"> div01</div> <div id="div03"> div03</div> <script type="text/javascript"><span style="color: #000000;"> window.onload = <span style="color: #0000ff;">function<span style="color: #000000;">(){ <span style="color: #0000ff;">var div01 = document.getElementById('div01'<span style="color: #000000;">); <span style="color: #0000ff;">var div02 = document.getElementById('div02'<span style="color: #000000;">); <span style="color: #0000ff;">var div03 = document.getElementById('div03'<span style="color: #000000;">); <span style="color: #008000;">//<span style="color: #008000;">output: div01:0 background: name:div01 console.log( 'div01:' + div01.offsetWidth + " background: " + div01.style.background + " name:" + div01.getAttribute("data-name"<span style="color: #000000;">)); <span style="color: #008000;">//<span style="color: #008000;">output: div02:100 name:div02 console.log( 'div02:' + div02.offsetWidth + " name:" + div02.getAttribute("data-name"<span style="color: #000000;">)); <span style="color: #008000;">//<span style="color: #008000;">output: div03:100 console.log( 'div03:' +<span style="color: #000000;"> div03.offsetWidth); div01.style.width = 1000<span style="color: #000000;">; div01.setAttribute("data-name","div0101"<span style="color: #000000;">); div02.style.width = "800px"<span style="color: #000000;">; div02.setAttribute("data-name","div0202"<span style="color: #000000;">); div03.style.width = 800<span style="color: #000000;">; <span style="color: #008000;">//<span style="color: #008000;">output: div01:0 background: name:div0101 console.log( 'div01:' + div01.offsetWidth + " background: " + div01.style.background + " name:" + div01.getAttribute("data-name"<span style="color: #000000;">)); <span style="color: #008000;">//<span style="color: #008000;">output: div02:800 name:div0202 console.log( 'div02:' + div02.offsetWidth + " name:" + div02.getAttribute("data-name"<span style="color: #000000;">)); <span style="color: #008000;">//<span style="color: #008000;">output: div03:800 console.log( 'div03:' +<span style="color: #000000;"> div03.offsetWidth); } </script>
2. Block
Set the element as a block-level element and apply box model related attributes. The default Width will be 100%, and the Height will be adaptive. Margin and padding are both valid. If no child elements occupying the width or height exist, the height is zero.
The code is as follows:
<span style="color: #0000ff;"><span style="color: #800000;">html</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">head</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">style</span><span style="color: #0000ff;">></span><span style="color: #800000; background-color: #f5f5f5;"> #div01</span><span style="color: #000000; background-color: #f5f5f5;">{</span><span style="color: #ff0000; background-color: #f5f5f5;"> background</span><span style="color: #000000; background-color: #f5f5f5;">:</span><span style="color: #0000ff; background-color: #f5f5f5;"> red</span><span style="color: #000000; background-color: #f5f5f5;">;</span> <span style="color: #000000; background-color: #f5f5f5;">}</span><span style="color: #800000; background-color: #f5f5f5;"> #div02</span><span style="color: #000000; background-color: #f5f5f5;">{</span><span style="color: #ff0000; background-color: #f5f5f5;"> height</span><span style="color: #000000; background-color: #f5f5f5;">:</span><span style="color: #0000ff; background-color: #f5f5f5;"> 100px</span><span style="color: #000000; background-color: #f5f5f5;">;</span><span style="color: #ff0000; background-color: #f5f5f5;"> background</span><span style="color: #000000; background-color: #f5f5f5;">:</span><span style="color: #0000ff; background-color: #f5f5f5;"> gray</span><span style="color: #000000; background-color: #f5f5f5;">;</span> <span style="color: #000000; background-color: #f5f5f5;">}</span><span style="color: #800000; background-color: #f5f5f5;"> #div03</span><span style="color: #000000; background-color: #f5f5f5;">{</span><span style="color: #ff0000; background-color: #f5f5f5;"> background</span><span style="color: #000000; background-color: #f5f5f5;">:</span><span style="color: #0000ff; background-color: #f5f5f5;"> green</span><span style="color: #000000; background-color: #f5f5f5;">;</span> <span style="color: #000000; background-color: #f5f5f5;">}</span> <span style="color: #0000ff;"></span><span style="color: #800000;">style</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></span><span style="color: #800000;">head</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">body</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="div01"</span> <span style="color: #0000ff;">></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="div02"</span> <span style="color: #0000ff;">></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">id</span><span style="color: #0000ff;">="div03"</span> <span style="color: #0000ff;">></span>div03<span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></span><span style="color: #800000;">body</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></span><span style="color: #800000;">html</span><span style="color: #0000ff;">></span></span></span></span></span></span></span></span>
Screenshot of effect:
Three, inline
Inline elements or those modified as inline elements through display:inline have the behavior of inline elements.
1) Multiple inline elements will line up in a row, and there will be a gap of about 8 pixels between multiple inline elements. The solution to the 8 pixel gap is:
a). The Html text is consciously arranged in one line, as shown in the following code:
<span style="color: #0000ff;"><span style="color: #800000;">a</span><span style="color: #0000ff;">></span>a01<span style="color: #0000ff;"></span><span style="color: #800000;">a</span><span style="color: #0000ff;">><span style="color: #800000;">a</span><span style="color: #0000ff;">></span>a02<span style="color: #0000ff;"></span><span style="color: #800000;">a</span><span style="color: #0000ff;">></span></span></span>
b). Use margin-left:-8px, which is a negative value for marginq. You can also use negative values for letter-spaceing and word-spaceing in the outer layer (such test elements need to reset the set attributes)
<span style="color: #800000;">.inline</span>{<span style="color: #ff0000;"> display</span>:<span style="color: #0000ff;"> inline</span>;<span style="color: #ff0000;"> background</span>:<span style="color: #0000ff;"> red</span>;<span style="color: #ff0000;"> margin</span>:<span style="color: #0000ff;"> 0px</span>;<span style="color: #ff0000;"> padding</span>:<span style="color: #0000ff;"> 10px</span>;<span style="color: #ff0000;"> margin-left</span>:<span style="color: #0000ff;"> -8px</span>; }
<span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="inline"</span><span style="color: #0000ff;">></span>inline01<span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="inline"</span><span style="color: #0000ff;">></span>inline02<span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="inline"</span><span style="color: #0000ff;">></span>inline03<span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="inline"</span><span style="color: #0000ff;">></span>inline04<span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></span></span></span></span>c). Add font-size:0px and -webkit-text-size-adjust:none to the outer element that wraps the inline element to achieve
<span style="color: #800000;">a</span>{<span style="color: #ff0000;"> background</span>:<span style="color: #0000ff;"> red</span>;<span style="color: #ff0000;"> font-size</span>:<span style="color: #0000ff;"> 14px</span>; }<span style="color: #800000;"> .overWidth</span>{<span style="color: #ff0000;"> white-space</span>:<span style="color: #0000ff;"> nowrap</span>;<span style="color: #ff0000;"> border</span>:<span style="color: #0000ff;"> 1px solid gray</span>;<span style="color: #ff0000;"> font-size</span>:<span style="color: #0000ff;"> 0px</span>;<span style="color: #ff0000;"> -webkit-text-size-adjust</span>:<span style="color: #0000ff;"> none</span>; }<span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="overWidth"</span> <span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">a</span><span style="color: #0000ff;">></span>a01<span style="color: #0000ff;"></span><span style="color: #800000;">a</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">a</span><span style="color: #0000ff;">></span>a000000002<span style="color: #0000ff;"></span><span style="color: #800000;">a</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></span></span></span>
2) The width and height of the Inline element are invalid
3) The padding of the Inline element is all valid, but the left and right margins are valid, and the up and down are invalid.
4) Inline elements wrap inline elements, and the width and height of the outer elements will be stretched by the inner ones
<span style="color: #800000;">.overWidth</span>{<span style="color: #ff0000;"> display</span>:<span style="color: #0000ff;"> inline</span>;<span style="color: #ff0000;"> border</span>:<span style="color: #0000ff;"> 1px solid gray</span>; }
<span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="overWidth"</span> <span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">a</span><span style="color: #0000ff;">></span>a01<span style="color: #0000ff;"></span><span style="color: #800000;">a</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">a</span><span style="color: #0000ff;">></span>a000000002<span style="color: #0000ff;"></span><span style="color: #800000;">a</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></span></span></span>
5) Block/inline-block elements wrap inline elements. By default, they automatically wrap when the width exceeds the width and the height expands.
a) Forcing no line breaks can be achieved through white-space:nowrap. At this time, the over-width will appear, and the display can be omitted through the combination of overflow:hidden and text-overflow:ellipsis.
<span style="color: #800000;">.overWidth</span>{<span style="color: #ff0000;"> white-space</span>:<span style="color: #0000ff;"> nowrap</span>;<span style="color: #ff0000;"> width</span>:<span style="color: #0000ff;"> 100px</span>;<span style="color: #ff0000;"> border</span>:<span style="color: #0000ff;"> 1px solid gray</span>;<span style="color: #ff0000;"> overflow</span>:<span style="color: #0000ff;"> hidden</span>;<span style="color: #ff0000;"> text-overflow</span>:<span style="color: #0000ff;"> ellipsis</span>; }<span style="color: #0000ff;"><span style="color: #800000;">div </span><span style="color: #ff0000;">class</span><span style="color: #0000ff;">="overWidth"</span> <span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">a</span><span style="color: #0000ff;">></span>a01<span style="color: #0000ff;"></span><span style="color: #800000;">a</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"><span style="color: #800000;">a</span><span style="color: #0000ff;">></span>a000000002<span style="color: #0000ff;"></span><span style="color: #800000;">a</span><span style="color: #0000ff;">></span> <span style="color: #0000ff;"></span><span style="color: #800000;">div</span><span style="color: #0000ff;">></span></span></span></span>

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.

HTML is a language used to build web pages, defining web page structure and content through tags and attributes. 1) HTML organizes document structure through tags, such as,. 2) The browser parses HTML to build the DOM and renders the web page. 3) New features of HTML5, such as, enhance multimedia functions. 4) Common errors include unclosed labels and unquoted attribute values. 5) Optimization suggestions include using semantic tags and reducing file size.


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

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Dreamweaver CS6
Visual web development tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment