设置div的最小高度

设置div的最小高度

本文介绍了jQuery - 设置div的最小高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这对大多数人来说很容易。但我需要一个小片段,查找一个div的当前高度(div具有基于其内部的内容的动态高度)
,然后在css类的min-height值中设置该值。

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 content inside it)and then set that value in the css class's min-height value.

基本上这意味着我想要这个容器的最小高度是与当前高度完全相同的值。这可能是一个快速:)

Basically what this means is that I want this container to have it's min-height to be the exact same value as it's current height. This is probably a quick one :)

推荐答案

只是一个概念的证明!

     // 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
            }
});

这应该可以正常工作!

这篇关于jQuery - 设置div的最小高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 05:19