简体   繁体   中英

How to prevent dynamically created table from overflowing its div?

Here is a picture of what is happening. I want vertical and horizontal scroll bars and the table to fill its container div and not overflow.

在此处输入图像描述

The dividers shown are from a jquery library called gridsplit.

<script src="dist/jquery.gridsplit.optimised.js"></script>

The table header is hard-coded but the body is created dynamically.

Here is the html from one attempt:

 <div style="float:left; overflow:auto; width:100%; height:95%">
            <div id="grid4" class="grid">
                <div class="innerGrid">
                    <div id="leftCol" class="gridColumn" gs-width="15%">
                        <div class="gridCell" gs-height="60%">
                            <div class="fillCell">
                                <div id="parent">
                                    <select id="selectWatchlist" style="float:left"><option value="My Portfolio">My Portfolio</option></select>
                                    <button id="addSymbol" type="button" class="btn btn-primary"> 
                                        <i class="glyphicon glyphicon-plus-sign"></i> Syms
                                    </button>
                                </div>
                                <div style="display:table-cell">
                                    <table id="watchlist" style="width:100%; border:0; cellpadding:0; cellspacing:0; margin-bottom:5px;">
                                        <tr>
                                            <th>Sym</th><th>Price</th><th>% Change</th>
                                        </tr>
                                    </table>     
                                </div>                       
                            </div>
                        </div>
                        <div class="gridCell" gs-height="40%">
                            <div class="fillCell"><a>Notes</a></div>
                        </div>

I've been googling all day and have tried dozens of combinations to no avail. Suggestions?

The solution was to simply add display:block like this:

.gridCell .fillCell {
  height: 100%;
  display: block;
  overflow:auto;
}

Now it has the scrollbars and doesn't overflow. Here is a picture:

在此处输入图像描述

I could swear I tried that, but apparently not.

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