Most people can easily confuse CSS property display with visibility, they seem to be no different, in fact, their differences are very large.
The visibility property is used to determine whether an element is displayed or hidden, which is represented by the visibility= "Visible|hidden" (visible indicates display, hidden indicates hidden).
When visibility is set to "hidden", the element is hidden, but it still occupies its original position. Cases:
<Scriptlanguage= "JavaScript"> functiontogglevisibility (Me) {if(me.style.visibility== "Hidden") {me.style.visibility="Visible"; } Else{me.style.visibility= "Hidden"; }}</Script> <Divonclick= "togglevisibility (this)"style= "Position:relative">
The first line of text will trigger the "hidden" and "visible" properties, noting the change in the second line. </div> <div> because visibility retains the position of the element, the first line is not visible but the position is still, and the second row does not move up or down. </div>
Notice that when the element is hidden, it is no longer possible to receive other events, so in the first code, when it is set to "hidden", it can no longer receive the response to the event, so it is not possible to click the first paragraph of the mouse to display the text. On the other hand, the display property is a little different.
The Visibility property is a hidden element but maintains the floating position of the element, and display is actually a floating feature of the set element.
When display is set to block, all elements in the container will be treated as a separate block, like the <div> element, which is placed on the page at that point. (You can actually set the <span> display:block so that it can work like <div>.)
Setting display to inline will make its behavior as inline as the element---even if it is an ordinary block element such as <DIV>, it will also be combined to image <span> that output stream. Here's a look at the code and effects of my example:
<Scriptlanguage= "JavaScript"> functionToggledisplay (Me) {if(Me.style.display=="Block") {Me.style.display="inline"; Alert ("the text is now: ' inline '."); } Else { if(Me.style.display=="inline") {Me.style.display="None"; Alert ("the text is now: ' None '. Automatically re-displays after 3 seconds. "); Window.settimeout ("bluetext.style.display= ' block ';", the,"JavaScript"); } Else{Me.style.display="Block"; alert ("the text is now: ' Block '."); } } } </Script><Div>in the<spanID= "Bluetext"onclick= "Toggledisplay (this)"style= "Color:blue;position:relative;cursor:hand;">Blue</span>Click on the text to see the effect.</Div>
Finally, display is set: None, when the element is actually removed from the page, and the element underneath it is automatically followed. (Display:none is applied at this point, the element is equivalent to vanishing, while the Visibility:hidden is only hidden, and the position is still.) )
The display properties are block, inline, none, and use Visibility:hidden, for example:
<H1>Display attributes are block, inline, none value and use Visibility:hidden;</H1> <P><SPANID= "Ospan"style= "Background-color: #CFCFCF;">This is a SPAN</SPAN>In a sentence.</P> <P> <inputtype=buttonvalue= "Inline"onclick= "ospan.style.display= ' inline '"> <inputtype=buttonvalue= "Block"onclick= "ospan.style.display= ' block '"> <inputtype=buttonvalue= "None"onclick= "ospan.style.display= ' None '"> <inputtype=buttonvalue= "Hidden"onclick= "ospan.style.visibility= ' hidden '"> <inputtype=buttonvalue= "Visible"onclick= "ospan.style.visibility= ' Visible '"> </P> <UL> <LI>Sets the element to block, and wraps the element after it.</LI> <LI>Setting an element to inline will eliminate the element wrapping.</LI> <LI>Set the element to none to hide the element content.</LI> </UL>
Style= "Visibility:hidden" and style= "Display:none" difference