简体   繁体   English

将内部div固定在外部div的顶部,并在滚动外部div时防止内部div在外部div上溢出

[英]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. 我一直试图在外部div的顶部修复内部div。
1.The inner div should have a wider width than the outer div 1,内部div的宽度应比外部div的宽
2.The outer div is scrollable and inner div should remain at the top of the outer div while scrolling. 2.外部div是可滚动的,内部div在滚动时应保持在外部div的顶部。

My problem is that the inner div longer stays inside the outer div. 我的问题是内部div停留在外部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/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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