简体   繁体   English

调整表格大小后,如何在单元格中调整DIV大小?

[英]How can I make a DIV resize in a cell when the table is resized?

I have an hourly timeline type view that is a table, then I have activities the stretch along the timeline for as long as the activities are. 我有一个每小时的时间线类型视图,它是一个表,然后我会沿着时间线进行活动,只要活动持续即可。 时间线视图

It works fine until I hit certain browser sizes, namely iPad in witch the divs will start to spill over into other hours. 在我达到特定的浏览器大小之前,它工作正常,例如,divs中的iPad将开始溢出到其他时间。 They should stop at the red line since the event is only til 12pm. 他们应在红线处停下,因为​​该事件直到下午12点为止。

Question is, how can I make the divs resize to stay within their boundaries? 问题是,如何使div调整大小以保持其边界内?

I am using Bootstrap 3.2 and Metronic template 我正在使用Bootstrap 3.2和Metronic模板

Thanks! 谢谢!

Here is the code. 这是代码。

<div class="row">
<div class="col-md-12" id="EventsDiv">
  <table class="table table-bordered" style="width:800px">
    <tbody>
      <tr>
        <th style="width:200px">Event</th>
        <th style="width:60px">6A</th>
        <th style="width:60px">7A</th>
        <th style="width:60px">8A</th>
        <th style="width:60px">9A</th>
        <th style="width:60px">10A</th>
        <th style="width:60px">11A</th>
        <th style="width:60px">12P</th>
        <th style="width:60px">1P</th>
        <th style="width:60px">2P</th>
        <th style="width:60px">3P</th>
      </tr>
      <tr>
        <td>Brad Storch
        <br />9:00 AM - 12:00 PM</td>
        <td id="ea-600AM"></td>
        <td id="ea-700AM"></td>
        <td id="ea-800AM"></td>
        <td id="ea-900AM">
          <div style="position:absolute; width:240px">
            <div style="width:240px; height:15px; position:absolute; top:0px;">
            Game Van</div>
          </div>
          <div style="position:absolute; width:180px">
            <div style="width:180px; height:15px; position:absolute; top:17px;">
            Hamster Ball</div>
          </div>
        </td>
        <td id="ea-1000AM"></td>
        <td id="ea-1100AM">
          <div style="position:absolute; width:120px">
            <div style="width:120px; height:15px; position:absolute; top:34px">
            Candy Cannon</div>
          </div>
        </td>
        <td id="ea-1200PM"></td>
        <td id="ea-100PM"></td>
        <td id="ea-200PM"></td>
        <td id="ea-300PM"></td>
      </tr>
    </tbody>
  </table>
</div>

I should try to use colspan and rowspan ; 我应该尝试使用colspanrowspan ; set the rowspan of the event name equal to the number of items and set the colspan of the items equal to the number of hours: 将事件名称的行rowspan设置为等于项目数,将项目的列rowspan设置为等于小时数:

<div class="container">
<div class="row">
<table border="1" width="100%">
       <tbody><tr>
        <th style="width:200px">Event</th>
        <th style="width:60px">6A</th>
        <th style="width:60px">7A</th>
        <th style="width:60px">8A</th>
        <th style="width:60px">9A</th>
        <th style="width:60px">10A</th>
        <th style="width:60px">11A</th>
        <th style="width:60px">12P</th>
        <th style="width:60px">1P</th>
        <th style="width:60px">2P</th>
        <th style="width:60px">3P</th>
      </tr>
 <tr> 
          <td rowspan="3">Brad Storch
        <br>9:00 AM - 12:00 PM
   </td>
        <td id="ea-600AM"></td>
        <td id="ea-700AM"></td>
        <td id="ea-800AM"></td>
        <td id="ea-900AM" colspan="4" style="background-color:red;">
         first
        </td>
        <td id="ea-100PM"></td>
        <td id="ea-200PM"></td>
        <td id="ea-300PM"></td>
</tr>
 <tr> 

        <td id="ea-600AM"></td>
        <td id="ea-700AM"></td>
        <td id="ea-800AM"></td>
        <td id="ea-900AM" colspan="3" style="background-color:yellow;">
                               Hamster Ball
        </td>
        <td id="ea-1200PM"></td>
        <td id="ea-100PM"></td>
        <td id="ea-200PM"></td>
        <td id="ea-300PM"></td>
      </tr>
 <tr> 
        <td id="ea-600AM"></td>
        <td id="ea-700AM"></td>
        <td id="ea-800AM"></td>
   <td id="ea-900AM"></td>
        <td id="ea-1000AM"></td>
        <td id="ea-1100AM" colspan="2" style="background-color:green;">

            Candy Cannon
        </td>
        <td id="ea-100PM"></td>
        <td id="ea-200PM"></td>
        <td id="ea-300PM"></td>
      </tr> 
</tbody></table>  
</div>
</div>

demo: http://www.bootply.com/lkpipTYtVt 演示: http : //www.bootply.com/lkpipTYtVt

Also notice that Bootstrap provide you 'responsive' table, which got scrollbars for small screen widths: http://getbootstrap.com/css/#tables-responsive 还要注意,Bootstrap为您提供了“响应式”表,该表具有用于较小屏幕宽度的滚动条: http : //getbootstrap.com/css/#tables-sensitive

Of course you can also use jQuery: 当然您也可以使用jQuery:

var cellWidth = $('#ea-600AM').innerWidth();
$('.hour4 div').css('width',cellWidth*4 + 3 + 'px').css('background-color','red');
$('.hour3 div').css('width',cellWidth*3 + 2 + 'px').css('background-color','green');
$('.hour2 div').css('width',cellWidth*2 + 1 + 'px').css('background-color','blue'); 

demo: http://www.bootply.com/SC93FAaHBG 演示: http : //www.bootply.com/SC93FAaHBG

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

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