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

后端 未结 9 612
遇见更好的自我
遇见更好的自我 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:38

    maybe something like

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

    just to add to the answers here, I was using the height as a function with two options either specify the height if it is less than the window height, or set it back to auto

    var windowHeight = $(window).height();
    $('div#someDiv').height(function(){
        if ($(this).height() < windowHeight)
            return windowHeight;
        return 'auto';
    });
    

    I needed to center the content vertically if it was smaller than the window height or else let it scroll naturally so this is what I came up with

    0 讨论(0)
  • 2020-12-13 23:46
    $('div#someDiv').removeAttr("height");
    
    0 讨论(0)
提交回复
热议问题