简体   繁体   中英

fix inner div at the top of outer div and when scrolling outer div, prevent inner div overflowing on the outer div

I have been trying to fix a inner div at the top of an outer div.
1.The inner div should have a wider width than the outer div
2.The outer div is scrollable and inner div should remain at the top of the outer div while scrolling.

My problem is that the inner div longer stays inside the outer div.


<div id="ScheduleHolder" style="height:100px; width:120px; overflow:scroll">

    <div id="2" valign="top" style="float:none; display:block; position:absolute !important; margin:0;">

        <table border="1" bgcolor="#99FF00">

          <tr>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>



          </tr>

        </table> 

    </div>



    <div id="3" style="float:left; display:block;">

       <table border="1">

          <tr>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>

            <th scope="col">&nbsp;</th>



          </tr>

          <tr>

            <th scope="row">&nbsp;</th>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

                            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

          </tr>

          <tr>

            <th scope="row">&nbsp;</th>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

                            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

          </tr>

          <tr>

            <th scope="row">&nbsp;</th>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

                            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

          </tr>

          <tr>

            <th scope="row">&nbsp;</th>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

                            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

          </tr>

          <tr>

            <th scope="row">&nbsp;</th>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

                            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

          </tr>

          <tr>

            <th scope="row">&nbsp;</th>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

                            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

          </tr>

          <tr>

            <th scope="row">&nbsp;</th>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

                            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

          </tr>

          <tr>

            <th scope="row">&nbsp;</th>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

                            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

          </tr>

          <tr>

            <th scope="row">&nbsp;</th>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

                            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

          </tr>

          <tr>

            <th scope="row">&nbsp;</th>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

            <td>&nbsp;</td>

          </tr>

        </table>



    </div>

    <div style="clear:both"></div>

</div>

好吧,只需将内部div放在外部div之外,然后将现在是外部div的内部div与外部div对齐,当然,现在内部div和您的内部div将出现在旧的内部div上,但是我们知道这是外面的div。

您想尝试使用DataTables jQuery插件来解决此问题: http : //datatables.net/

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