Home >Web Front-end >CSS Tutorial >Solve the difference between display and visibility in CSS_Basic Tutorial

Solve the difference between display and visibility in CSS_Basic Tutorial

WBOY
WBOYOriginal
2016-05-16 12:08:492074browse

Most people easily confuse the CSS properties display and visibility. They seem to be the same, but in fact they are very different.
The visibility attribute is used to determine whether the element is displayed or hidden, which is represented by visibility="visible|hidden" (visible means displayed, hidden means hidden).
When visibility is set to "hidden", although the element is hidden, it still occupies its original position. Example:


[Ctrl A Select all Note:If you need to introduce external Js, you need to refresh to execute]

Note that when the element is hidden, it can no longer receive other events. , so in the first piece of code, when it is set to "hidden", it can no longer receive response events, so it cannot be displayed by clicking the mouse on the first piece of text.
On the other hand, the display attribute is a little different. The visibility attribute hides the element but maintains its floating position, while display actually sets the floating characteristics of the element.
When display is set to block, all elements in the container will be treated as a single block, just like the
element, which will be placed into the page at that point. (You can actually set the display:block of so that it works like
.
Setting the display to inline will make it behave like the element is inline --- even if it is a normal block element like
, It will also be combined into an output stream like .
Look at the code and effects of my example below:

[Ctrl A Select all Note:If you need to introduce external Js, you need to refresh it before it can be executed]

At the same time, about the difference between display:inline; and float:left; You can refer to this article:
(display refers to the display state, inline means inline, which is characterized by being close to the previous inline element. Usually the default inline elements include span, a, em, strong, etc. And float It represents float, float:left, which is the floating form for block-level elements and is two states of different forms.)
http://www.andymao.com/andy/post/42.html
http://bbs.blueidea.com/thread-2596793-1-1.html

[Ctrl A Select all Note:If you need to introduce external Js, you need to refresh it before it can be executed]

Solution:
After checking the CSS manual, I found that the hidden content turned out to be there The difference is that one retains the physical space of the object and the other does not.
----------------------------------
display:none
CSS1 Hidden object. Unlike the hidden value of the visibility attribute, it does not reserve its physical space for the hidden object

visibility:hidden
Object hiding, unlike the display attribute, this attribute reserves the physical space it occupies for the hidden object space.

But because visibility:hidden is used, the elongated content is actually the DIV containing the image; but after using display:none, it becomes normal. I had always suspected that it was a problem with the high settings, but I didn
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn