Hide div but keep the empty space

后端 未结 5 1717
庸人自扰
庸人自扰 2021-02-01 00:17

I have the following div element:

相关标签:
5条回答
  • 2021-02-01 00:42

    And another option for the sake of completeness. Toggle opacity:

    $(".description").css('opacity', 0); // hide
    $(".description").css('opacity', 1); // show
    

    http://jsfiddle.net/KPqwt/

    However using visibility is prefered for this task.

    0 讨论(0)
  • 2021-02-01 00:43

    Try:

    $(".description").css("visibility", "hidden")
    

    hide() is the equivalent to: $(".description").css("display", "none");

    Which does not reserve the space the element was taking.

    Hidden makes the element invisible, but stills reserves the space.

    0 讨论(0)
  • 2021-02-01 00:52

    you can wrap another div around the outside of it, and probably tell it a specific height to occupy. that way your inner div can show and hide and fadeOut, etc, and the outer div will hold down the real-estate on the page.

    0 讨论(0)
  • 2021-02-01 01:03

    It's important to note that dfsq's example using Opacity:0 will still allow the contents to be selected, copy/pasted, etc., although there is no visible text-highlighting when selecting.

    0 讨论(0)
  • 2021-02-01 01:07

    Use visibility css property for this

    visibility:

    The visibility property specifies whether the boxes generated by an element are rendered.

    $(".description").css('visibility', 'hidden');
    

    Demo: Fiddle

    0 讨论(0)
提交回复
热议问题