简体   繁体   中英

max-height 100% overflowing parent

I have a list-group using bootstrap, with a lot of items in it. I applied the following css rules to the id of my list-group div.

#my-listgroup {
    margin-top: 20px;
    border-radius: 6px;
    overflow-y: scroll;
    max-height: 100%;
    max-width: 100%;
    width: auto;
    height: auto;
}

Now this div is wrapped in a couple of other divs, as shown below.

我的问题的标记。

how do I make my listgroup not overflow my #body-content-menu div who has the following css rules, while still allowing this to be responsive.

#body-content-menu {
    border-radius: 10px;
    height: 100%;
    background-color: #B21E15;
    padding-bottom: 20px;
}

Firstly you must have a jquery link in you page(Maybe bootstrap add it to your page). Then you need to set an id for div class="row" for example id="row and another id for div class="col-lg-12" for example id="col" .

Now:

var realHeight = $('#col').height() - $('#row').height();
$('#my-listgroup').css('height', realHeight + 'px');

 <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script> <div id="col" style="height:100px;background-color:red;margin:100px;"> <div id="row" style="height:40px;">div row</div> <select id="my-listgroup" size="4" name="ctl02" style="max-height: 100%;"> <option value="item">item</option> <option value="item">item</option> <option value="item">item</option> <option value="item">item</option> <option value="item">item</option> <option value="item">item</option> </select></div> <script> var realHeight = $('#col').height() - $('#row').height(); $('#my-listgroup').css('height', realHeight + 'px'); </script> 

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