JQuery css max-height 不起作用

Omi*_*mid 4 html javascript css jquery

我已经.css('max-height','auto')在 JQuery 中测试了设置css 属性的这段代码,但它不起作用,当我设置一个维度时,.css('max-height','93px')它工作正常,我该如何将其设置为auto

HTML:

<div class="holder">
    <div>DIVISION</div>
    <div>DIVISION</div>
    <div>DIVISION</div>
    <div>DIVISION</div>
    <div>DIVISION</div>
    <div>DIVISION</div>
    <div>DIVISION</div>
</div>
<br />
<input type="button" onclick="test();" value="CHECK" />
Run Code Online (Sandbox Code Playgroud)

CSS:

.holder{
    max-height:40px;
    background:red;
    padding:10px;
    overflow:hidden;
}
.holder div{
    background:blue;
    margin:3px 0;
}
Run Code Online (Sandbox Code Playgroud)

js:

function test(){
    var hldr=$('.holder'); //get element

    alert('before set: ' + $('.holder').css('max-height')); //alert before set

    /* SET */
    hldr.css('max-height','auto');

    alert('after set: ' + $('.holder').css('max-height'));//alert after set
}
Run Code Online (Sandbox Code Playgroud)

http://jsfiddle.net/silverlight/23UCV/2/

Ram*_*kee 8

我也遇到过同样的问题。

我试过maxHeight属性。现在问题已经解决

$('#exampleId').css({"maxHeight":"100px"});
Run Code Online (Sandbox Code Playgroud)


Omr*_*ron 2

更改max-heightheight解决您的问题。

演示