How do I remove the height style from a DIV using jQuery?

后端 未结 9 611
遇见更好的自我
遇见更好的自我 2020-12-13 23:04

By default, a DIV\'s height is determined by its contents.

But, I override that and explicitly set a height with jQuery:

$(\'div#someDiv\').height(so         


        
相关标签:
9条回答
  • 2020-12-13 23:26

    you can try this:

    $('div#someDiv').height('');
    
    0 讨论(0)
  • 2020-12-13 23:27
    $('div#someDiv').css('height', '');
    
    0 讨论(0)
  • 2020-12-13 23:30

    Thank guys for showing all those examples. I was still having trouble with my contact page on small media screens like below 480px after trying your examples. Bootstrap kept inserting height: auto.

    Element Inspector / Devtools will show the height in:

    element.style {
    
    }
    

    In my case I was seeing: section#contact.contact-container | 303 x 743 in the browser window.

    So the following full-length works to eliminate the issue:

    $('section#contact.contact-container').height('');

    0 讨论(0)
  • 2020-12-13 23:33

    to remove the height:

    $('div#someDiv').css('height', '');
    $('div#someDiv').css('height', null);
    

    like John pointed out, set height to auto:

    $('div#someDiv').css('height', 'auto');
    

    (checked with jQuery 1.4)

    0 讨论(0)
  • 2020-12-13 23:33

    To reset the height of the div, just try

    $("#someDiv").height('auto');

    0 讨论(0)
  • 2020-12-13 23:36
    $('div#someDiv').height('auto');
    

    I like using this, because it's symmetric with how you explicitly used .height(val) to set it in the first place, and works across browsers.

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