简体   繁体   中英

Dynamically change the size of a div based on content

I have a view that slides into a div using angular. My problem is, the content is dynamic and the height of that view is going to change. How can I set the height of my outer div to fit the height of the inner div? Also, my inner div has to have position: absolute in order to use the css sliding class that slides the view into place.

Also worth mentioning that if I log:

console.log($("#item-container").height());

I get 163px which is the height of one category column in the row

Outer div

<div data-ng-app="items">
    <div ng-controller="ParentController">
        <div data-ng-view class="slide-left">

        </div>
    </div>
</div>

Inner div

<div class="container" id="item-container">
    <div data-ng-repeat="c in categories">
        <div ng-class="{true: 'row'}[$index % 3 == 2]">
            <div class="col-sm-4">
                <div class="row">
                    <label>{{c.Name}}</label>
                </div>
                <a class="row" href="#!/categories/{{c.CategoryID}}">
                    <img src="/images/thumb/NoImageAvailable.jpg" class="categoryBackground" />
                </a>
            </div>
        </div>
    </div>
</div>

set

<div style="display:inline-block"></div> for all

else use css

div
{
    display:inline-block;    
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM