Is there an opposite to display:none?

后端 未结 15 1683
夕颜
夕颜 2020-12-22 19:47

The opposite of visibility: hidden is visibility: visible. Similarly, is there any opposite for display: none?

Many people be

15条回答
  •  执笔经年
    2020-12-22 19:56

    Like Paul explains there is no literal opposite of display: none in HTML as each element has a different default display and you can also change the display with a class or inline style etc.

    However if you use something like jQuery, their show and hide functions behave as if there was an opposite of display none. When you hide, and then show an element again, it will display in exactly the same manner it did before it was hidden. They do this by storing the old value of the display property on hiding of the element so that when you show it again it will display in the same way it did before you hid it. https://github.com/jquery/jquery/blob/740e190223d19a114d5373758127285d14d6b71e/src/css.js#L180

    This means that if you set a div for example to display inline, or inline-block and you hide it and then show it again, it will once again show as display inline or inline-block same as it was before

    hello
    hello2
    hello3

    script:

      $('a').click(function(){
            $('div').toggle();
        });
    

    Notice that the display property of the div will remain constant even after it was hidden (display:none) and shown again.

提交回复
热议问题