


What are the differences between display:none and visibility:hidden
My answer at the time was that both can hide elements, but setting the element to display:none; after that, the document flow space previously occupied by the element will be canceled at the same time, but visibility:hidden; Even if the element is not displayed, it will still occupy space.
It was a telephone interview. After I answered, the other party did not continue to ask about display-related knowledge.
Now that I think about it, I am really lucky. If someone asks me about display-related knowledge, what should I pay attention to when using display:inline-block? I definitely won't be able to fight.
A few days agoExerciseWhen writing Navigation, since it is always necessary to set some inline elements or block-level elements to inline block-level elements, I just Thought of display:inline-block
However, I found that this is a attribute value that still has some knowledge. Recommend this article.
Inline-block has been supported since IE5.5, but you must know that IE5.5 was officially launched in 2000, but W3C This attribute value was only added to the CSS2.1 draft in 2002.
Block-level elements in IE 5.5, 6, 7, and 8 (Q) have incomplete support for inline-block. If you want to achieve similar effects, you need to set it to display:inline first. Then use zoom:1 and so on to trigger
hasLayout
(this is the reason for the bug in IE browser, I will write about it in detail). For inline elements in IE 5.5, 6, 7, and 8 (Q), if you want to achieve the effect of inline-block, you only need to directly set this attribute value or use zoom:1, etc.
The following are for IE 5.5, 6, 7, 8 (Q) browsers
Inline element display:inline-block
You only need to perform display:inline-block, or zoom:1; on the inline element to trigger hasLayout, and then you can set the width and height of the inline element.
display:inline-block;*
zoom:1;
Add*
in front of zoom so that this attribute can only be used for IE browsers Identify. There are other ways. Here is a detailed explanationBlock-level element display:inline-block
The block-level element triggers hasLayout through display:inline-block, which does not make the block-level element have the feature of not wrapping. . This is also a manifestation of incomplete support. The method to make up for it is:
display:inline; zoom:1;
First convert it into an inline element, and then make it have a layout.-
Combined with modern browsers, when we want to convert an element into an inline block-level element, all we need to do is:
`display:inline-block;`/*兼容现代浏览器,IE6、7 行内元素*/ `*display:inline;`/*兼容IE6、7块级元素*/
Copy after login*zoom :1
;
[Another problem caused by inline elements] is that there will be a certain amount of blank margin between inline elements. This is why.
I didn’t understand it when I wrote the last note, but after reading the blog I just recommended, I understand it. The browser renders inline elements as if it is rendering the words in a paragraph, or the word ,
There is a space between hello and buddy when we write,<p>hello buddy</p>
Copy after loginis written inline elements, each in-line element will be wrapped habitually
<span>hello</span> <span>buddy</span>
Copy after loginNormally, for multiple consecutive whitespace characters (spaces, line feeds, carriage returns, etc.), the browser will Combined into a single whitespace character.
How to remove white space between inline elements
Use font-size# on the parent element of the inline element ##:0px;
Except for versions before IE6, 7 and safri5, this method can be used to remove the white space of inline elements.font-size:0px;
Copy after login- Perform
letter-spacing on the parent element of the inline elementThis method can remove the white space between the inline elements in versions prior to safri5.
The white space between inline elements is related to the font size. The larger the font size, the larger the gap. When the absolute value of the negative value of letter-spacing is greater than the gap size, internal inline elements will overlap.letter-spacing:-2px;//这个2px等于元素之间的间隙
Copy after login - Perform parent elements of inline elementsThe above writing method is basically compatible with various browsers.
font-size:0;/* 所有浏览器 */ letter-spacing:-5px;/* Safari 等不支持字体大小为 0 的浏览器 */ `*letter-spacing:normal;` word-spacing:-1px;/* IE6、7 */
Copy after loginIt should be noted that in order to avoid conflicts between letter-spacing and word-spacing in IE6 and 7, letter-spacing needs to be hacked.
由于这些文本属性都会继承下去,造成行内元素内部的文字内容受到影响,所以需要为行内元素内部重新设置字体属性值。
font-size: 12px; letter-spacing: normal; word-spacing: normal;
Copy after login刚才推荐的那篇文章,总结了代码如下:
.dib-wrap修饰行内元素的父级元素,.dib修饰行内元素,另外需要注意由于 inline-block 具有 inline 元素的特性,在垂直方向上很多时候我们并不希望元素以「vertical-align:baseline」方式来呈现,所以在「.dib-wrap」中统一重置为「vertical-align:top」即可.dib-wrap { font-size:0;/* 所有浏览器 */ *word-spacing:-1px;/* IE6、7 */ } .dib-wrap .dib{ font-size: 12px; letter-spacing: normal; word-spacing: normal; vertical-align:top; } @media screen and (-webkit-min-device-pixel-ratio:0){ /* firefox 中 letter-spacing 会导致脱离普通流的元素水平位移 */ .dib-wrap{ letter-spacing:-5px;/* Safari 等不支持字体大小为 0 的浏览器, N 根据父级字体调节*/ } } .dib { display: inline-block; `*display:inline;` `*zoom:1;` }
Copy after login
【相关推荐】
1. 免费html在线视频教程
2. html开发手册
The above is the detailed content of What are the differences between display:none and visibility:hidden. For more information, please follow other related articles on the PHP Chinese website!

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

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

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Export password-protected PDF in Photoshop: Open the image file. Click "File"> "Export"> "Export as PDF". Set the "Security" option and enter the same password twice. Click "Export" to generate a PDF file.

H5. The main difference between mini programs and APP is: technical architecture: H5 is based on web technology, and mini programs and APP are independent applications. Experience and functions: H5 is light and easy to use, with limited functions; mini programs are lightweight and have good interactiveness; APPs are powerful and have smooth experience. Compatibility: H5 is cross-platform compatible, applets and APPs are restricted by the platform. Development cost: H5 has low development cost, medium mini programs, and highest APP. Applicable scenarios: H5 is suitable for information display, applets are suitable for lightweight applications, and APPs are suitable for complex functions.

The necessity of registering VueRouter in the index.js file under the router folder When developing Vue applications, you often encounter problems with routing configuration. Special...

The key differences between CentOS and Ubuntu are: origin (CentOS originates from Red Hat, for enterprises; Ubuntu originates from Debian, for individuals), package management (CentOS uses yum, focusing on stability; Ubuntu uses apt, for high update frequency), support cycle (CentOS provides 10 years of support, Ubuntu provides 5 years of LTS support), community support (CentOS focuses on stability, Ubuntu provides a wide range of tutorials and documents), uses (CentOS is biased towards servers, Ubuntu is suitable for servers and desktops), other differences include installation simplicity (CentOS is thin)

Detailed explanation of XPath search method under DOM nodes In JavaScript, we often need to find specific nodes from the DOM tree based on XPath expressions. If you need to...

不同数据库系统添加列的语法为:MySQL:ALTER TABLE table_name ADD column_name data_type;PostgreSQL:ALTER TABLE table_name ADD COLUMN column_name data_type;Oracle:ALTER TABLE table_name ADD (column_name data_type);SQL Server:ALTER TABLE table_name ADD column_name data_

There are differences in the promotion methods of H5 and mini programs: platform dependence: H5 depends on the browser, and mini programs rely on specific platforms (such as WeChat). User experience: The H5 experience is poor, and the mini program provides a smooth experience similar to native applications. Communication method: H5 is spread through links, and mini programs are shared or searched through the platform. H5 promotion methods: social sharing, email marketing, QR code, SEO, paid advertising. Mini program promotion methods: platform promotion, social sharing, offline promotion, ASO, cooperation with other platforms.

The C language function library is a toolbox containing various functions, which are organized in different library files. Adding a library requires specifying it through the compiler's command line options, for example, the GCC compiler uses the -l option followed by the abbreviation of the library name. If the library file is not under the default search path, you need to use the -L option to specify the library file path. Library can be divided into static libraries and dynamic libraries. Static libraries are directly linked to the program at compile time, while dynamic libraries are loaded at runtime.
