Difference between CSS display: none and visibility: hidden

Source: Internet
Author: User

The difference between CSS display: none and visibility: hidden is described here. Visibility: hidden is hidden, but the position is retained during browsing. CSS display: none is regarded as nonexistent and not loaded!

 

 

Do you know the difference between CSS display: none and visibility: hidden? Here we will share with you the HTML element (object) after the CSS display: None attribute is used) the width, height, and other attribute values are "lost". After the visibility: hidden attribute is used, the HTML element (object) is only invisible visually (completely transparent ), the space occupied by it still exists.

Difference between CSS display: none and visibility: hidden

Visibility: hidden, but its position is retained during browsing. CSS display: none is regarded as nonexistent and not loaded!

Overflow attribute value {visible | hidden | scroll | auto} is required only when the width and height of the DIV are limited ). The two are hidden HTML elements, which have no difference in visual effects, but they are still different in some Dom operations.

CSS display: none;

When this attribute is used, various attribute values, such as the width and height of the HTML element (object), will be "lost ";

Visibility: hidden;

After this attribute is used, the HTML element (object) is only visually invisible (completely transparent), and the space occupied by it still exists, that is to say, it still has attribute values such as height and width.

For details about the differences, see the demo.CodeRight:

  1. <! Doctypehtmlpublic "-// W3C // dtdxhtml1.0transitional // en"
  2. Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
  3. <HtmlxmlnsHtmlxmlns= "Http://www.w3.org/1999/xhtml"Lang= "Gb2312"> 
  4. <Head> 
  5. <Head> 
  6. <Title>Example: difference between CSS display: none and visible: hidden</Title> 
  7. <Metahttp-equivMetahttp-equiv="Content-Type "content =" text/html;Charset=Gb2312"/> 
  8. <Metahttp-equivMetahttp-equiv="Content-Type "content =" text/html;Charset=Gb2312"/> 
  9. <MetanameMetaname= "Author"Content= "Fengyan, CnLei.y.l@gmail.com"> 
  10. <MetanameMetaname= "Copyright"Content= "Http://www.cnlei.com"/> 
  11. </Head> 
  12. <Body> 
  13. <P><AhrefAhref= "Javascript: Alert ($ ('cnlei _ 1'). innerhtml + 'width: \ N'
  14. + Getxywh ($ ('cnlei _ 1'). W );">Click Here CSS display: none;</A></P> 
  15. <P><AhrefAhref= "Javascript: Alert ($ ('cnlei _ 2'). innerhtml + 'width: \ N'
  16. + Getxywh ($ ('cnlei _ 2'). W );">Click Here visibility: hidden;</A></P> 
  17. <DividDivid= "Cnlei_1"Style= "CSS display: none ;">Cnlei_1</Div> 
  18. <DividDivid= "Cnlei_2"Style= "Visibility: hidden ;">Cnlei_2</Div> 
  19.  
  20. <ScripttypeScripttype="Text/JavaScript"> 
  21. Varw3c= (Document. getelementbyid )? True: false;
  22. Varagt=Navigator. Useragent. tolowercase ();
  23. Varie= (AGT. indexof ("MSIE ")! =-1)
  24. & (AGT. indexof ("Opera") =-1) & (AGT. indexof ("omniweb") =-1 ));
  25. Varie5= (W3C & IE )? True: false;
  26. Varns6= (W3C &&(Navigator. appname= "Netscape "))? True: false;
  27.  
  28. Function $ (o ){
  29. Returndocument. getelementbyid (o )? Document. getelementbyid (o): O;
  30. }
  31.  
  32. Functiongetxywh (o ){
  33. Varo= $ (O );
  34. Varnlt=0;
  35. Varntop=0;
  36. Varoffsetparent= O;
  37. While (offsetparent! = NULL & offsetparent! = Document. Body ){
  38. Nlt + = offsetparent. offsetleft;
  39. Ntop + = offsetparent. offsettop;
  40. If (! Ns6 ){
  41. Parseint (offsetparent. currentstyle. borderleftwidth)>0?
  42. Nlt + = parseint (offsetparent. currentstyle. borderleftwidth ):"";
  43. Parseint (offsetparent. currentstyle. bordertopwidth)>0?
  44. Ntop + = parseint (offsetparent. currentstyle. bordertopwidth ):"";
  45. }
  46. OffsetparentOffsetparent= Offsetparent. offsetparent;
  47. }
  48. Return {X: nlt, Y: ntop, W: O. offsetwidth, H: O. offsetheight };
  49. }
  50. </Script> 
  51. </Body> 
  52. </Html> 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.