开发者

How to make a div invisible without commenting it out?

开发者 https://www.devze.com 2023-01-03 01:05 出处:网络
Is it pos开发者_Python百科sible to make a div invisible without commenting it out?If so, how?You need to hide that with CSS:

Is it pos开发者_Python百科sible to make a div invisible without commenting it out? If so, how?


You need to hide that with CSS:

div {                    /* this will hide all divs on the page */
  display:none;
}

If it is a particular div with certain class or id, you can hide it like:

<div class="div_class_name">Some Content</div>

CSS:

div.div_class_name {     /* this will hide div with class div_class_name */
  display:none;
}

Or

<div id="div_id_name">Some Content</div>

CSS:

div#div_id_name {        /* this will hide div with id div_id_name */
  display:none;
}

Note: You need to wrap CSS tyles in between <style type="text/css"></style> tags, example:

<style type="text/css">
  div#div_id_name {
    display:none;
  }
</style>

More Information :)


You can do this by inline style

<div style="display:none"></div>

or by defining CSS Style like In css add

.HideableDiv{display:none;}

and in your HTML write

<div class="HideableDiv" ></div>


Its Easy. The only thing you need is, adding a style to it, like following example shows:

CSS:

<style type="text/css">
    div.myInvisibleDiv {
        overflow: hidden;
        visibility: hidden;
        height: 0;
        width: 0;
    }
</style>

HTML:

<div class="myInvisibleDiv"><p>My invisible content</p></div>

This div, and it content does definitely not show, and it wont disturb surrounding elements.


if you want it to be essentially gone from your layout:

.element_class {
 display:none;
}

if you want to just make it invisible (but still keeping it's space seemingly empty)

.element_class {
 visibility: hidden;
}

and then your element (if a div) would look like this:

<div class="element_class"></div>

basically anything you add the class="element_class" to will be either invisible or completely hidden.


position: absolute;
left: -99999px; /* big number */

will make the content accessible to most screen readers but will render the element off-screen.


May be, its not the required solution, but you can tackle this kind of issues by these little tricks.

You can use jQuery to achieve the solution. If you want to totally hide/show the div, then you can use:

$('#my_element').show()
$('#my_element').hide()

Or if you want that your div become invisible and its still existing in the page, then you can use efficient trick:

$('#my_element').css('opacity', '0.0');    // invisible Maximum
$('#my_element').css('opacity', '1.0');   // visible maximum
0

精彩评论

暂无评论...
验证码 换一张
取 消