jQuery - Set min-height of div

前端 未结 3 1906
野的像风
野的像风 2020-12-09 16:14

This is probably really easy for most of you. But I\'m in need of a small snippet that looks up the current height of a div (the div has a dynamic height based on the conten

相关标签:
3条回答
  • 2020-12-09 16:33
    var elt = document.getElementById("<%= this.your_element_id.ClientID %>");
    elt.style.minHeight = elt.clientHeight + 'px';
    
    0 讨论(0)
  • 2020-12-09 16:39

    just a proof of concept!

         // attend for dom ready
        $(function() {
            // hide .foo before we get it's height
            $('.foo').hide();
            // get the height, also the one mentioned below is a good one!
            var foo_height = $('.foo').height();
            // see if the actual height respect our needs! esample 180px
            if ( foo_height > 180 ) {
                // set the height and show it!
                //$('.foo').css('height', foo_height + 'px').show(); OR try
                $('.foo').height( foo_height ).show();
            } else {
                //do something else here
                }
    });
    

    this should work as expected!

    0 讨论(0)
  • If I understand you correctly, you could do the following:

    $(".foo").css("min-height", function(){ 
        return $(this).height();
    });
    
    0 讨论(0)
提交回复
热议问题