开发者

flexible height for div?

开发者 https://www.devze.com 2023-04-11 23:16 出处:网络
I have a container div that need to be flexible in height because the content inside the div can change when users click on the button.

I have a container div that need to be flexible in height because the content inside the div can change when users click on the button.

<div id="container">
        <div id="divBuyNow">
            <button id="btnBuyNow">
                Buy Now</button>
        </div>
</div>

$("#btnBuyNow").clic开发者_开发百科k(function () {

                $("#divBuyNow").animate({
                    opacity: 0,
                    marginRight: '200px'
                }, 1000, function () {
                    $("#divBuyNow").hide();
                });


                $("#platformsContainer").animate({
                    opacity: 1,
                    marginRight: '170px'
                }, 2000);
            });


What I understand is you want to animate platformContainer to height based on the content. If yes, set overflow:hidden to container and modify contents to innerDiv inside the container with opacity:0. When you want to show, get the height of innerDiv and animate container div to height + margins and other offset.


If you dont mess up something in styles and you dont set height for that div, it will be flexible ;-) (from code i see above it seems that your button is there all the time and you are only hiding it...)


A div tag by default will be flexible in height and width(it adjusts itself according to the content placed inside it). You should be fine as long as you do not set the height and width css properties explicitly.
Just a note : In case of nested divs just be sure that you do not set the height and width property of the inner div. If you do so the outer div becomes inflexible i.e it will have the dimensions of the child div.

0

精彩评论

暂无评论...
验证码 换一张
取 消