{"id":14,"date":"2024-11-05T15:15:59","date_gmt":"2024-11-05T15:15:59","guid":{"rendered":"https:\/\/programming.rexthestrange.com\/?p=14"},"modified":"2024-11-17T15:22:09","modified_gmt":"2024-11-17T15:22:09","slug":"hiding-stuff","status":"publish","type":"post","link":"https:\/\/programming.rexthestrange.com\/?p=14","title":{"rendered":"Hiding stuff"},"content":{"rendered":"\n<p>There are three ways to hide an element in CSS:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>display:hidden<\/li>\n<\/ol>\n\n\n\n<p>Using display:hidden removes an element from the layout completely. It doesn&#8217;t take space on the page.<\/p>\n\n\n\n<p>Pros: <\/p>\n\n\n\n<p>It removes an element from the layout completely. It doesn&#8217;t take space on the page.<\/p>\n\n\n\n<p>Cons: <\/p>\n\n\n\n<p>If used, then you must &#8220;remember&#8221; what the actual display type is for when you want to show the element.<\/p>\n\n\n\n<p>It can also cause your layout to &#8220;jump around&#8221; when the element is added or removed unless you have static sizes defined.<\/p>\n\n\n\n<p>2. visibility:hidden<\/p>\n\n\n\n<p>Using visibility:hidden hides the element but it does not remove it from the page layout. You cannot interact with elements with visibility set to hidden.<\/p>\n\n\n\n<p>Pros:<\/p>\n\n\n\n<p>It does not cause elements to &#8220;jump&#8221; as the element is still there, still takes space on the page, it&#8217;s just that you can&#8217;t see it.<\/p>\n\n\n\n<p>Cons:<\/p>\n\n\n\n<p>If you want the element to be removed completely, then this will not work for you as it still takes space.<\/p>\n\n\n\n<p>Workaround:<\/p>\n\n\n\n<p>Setting width:0 and height:0 will have the same effect as display:none &#8211; it will take the element out of the page layout (actually, it is still in the page layout, it&#8217;s just that it has no width or height and, as such, appears to have been removed). The trade-off is, if you have a defined width or height, then these must be &#8220;remembered&#8221; in order to restore the element.<\/p>\n\n\n\n<p>3. opacity:0<\/p>\n\n\n\n<p>Setting opacity to 0 has the same effect as visibility:hidden &#8211; it is removed from sight but still takes space on the page, however, unlike elements with visibility set to hidden, you can interact with elements with opacity set to 0.<\/p>\n\n\n\n<p>Pros:<\/p>\n\n\n\n<p>Not exactly &#8220;hiding&#8221; the element, opacity can also be used for its intended purpose: to make an element partially visible. This is particularly handy for creating an element to cover another element and to &#8220;dim&#8221; it  (like a black screen under a popup window) by setting the value to 0.5 or 50%, for example.<\/p>\n\n\n\n<p>Cons:<\/p>\n\n\n\n<p>Same as visibility:hidden. The same workaround can be used.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>There are three ways to hide an element in CSS: Using display:hidden removes an element from the layout completely. It doesn&#8217;t take space on the page. Pros: It removes an element from the layout completely. It doesn&#8217;t take space on the page. Cons: If used, then you must &#8220;remember&#8221; what the actual display type is [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-14","post","type-post","status-publish","format-standard","hentry","category-css"],"_links":{"self":[{"href":"https:\/\/programming.rexthestrange.com\/index.php?rest_route=\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/programming.rexthestrange.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/programming.rexthestrange.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/programming.rexthestrange.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/programming.rexthestrange.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=14"}],"version-history":[{"count":3,"href":"https:\/\/programming.rexthestrange.com\/index.php?rest_route=\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":22,"href":"https:\/\/programming.rexthestrange.com\/index.php?rest_route=\/wp\/v2\/posts\/14\/revisions\/22"}],"wp:attachment":[{"href":"https:\/\/programming.rexthestrange.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/programming.rexthestrange.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/programming.rexthestrange.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}