表格有大量的列(30列),並且每個th
標籤都有white-space:nowrap
樣式在其上設置。這延伸了父div。如何防止這種情況發生,併爲div分配一個水平滾動條。 ?div內的表格水平拉伸div超過100%
<style>
.monthly_rental_payment_daily th {
white-space: nowrap;
}
.monthly_rental_payment_daily td {
white-space: nowrap;
}
</style>
<div style="width: 100%;" class="dashboardBox" id="dashboard-monthly-rental-payment">
<div class="dashboardBoxTitle" id="dashboard-monthly-rental-payment-title">
<span>Monthly Rental Payments</span>
</div>
<div style="height:auto" class="dashboardBoxBody"
id="dashboard-monthly-rental-payment-body">
<table
class="monthly_rental_payment_daily tablesorter standardTable">
<thead>
<tr>
<th style="text-align: left;padding-right: 15px">Location</th>
<th class="left" style="padding-right: 15px">Total to be paid</th>
<th class="left" style="padding-right: 15px">Total paid to date</th>
<th style="padding-right: 15px"></th>
<th class="left" style="padding-right: 15px">Total still to be paid</th>
<th style="padding-right: 15px"></th>
<th class="left" style="padding-right: 15px">1st - 7th</th>
<th style="padding-right: 15px"></th>
<th class="left" style="padding-right: 15px">8th-14th</th>
<th style="padding-right: 15px"></th>
<th class="left" style="padding-right: 15px">15th-21st</th>
<th style="padding-right: 15px"></th>
<th class="left" style="padding-right: 15px">22nd+</th>
<th style="padding-right: 15px"></th>
<th class="left" style="padding-right: 15px">1st - 7th</th>
<th style="padding-right: 15px"></th>
<th class="left" style="padding-right: 15px">8th-14th</th>
<th style="padding-right: 15px"></th>
<th class="left" style="padding-right: 15px">15th-21st</th>
<th style="padding-right: 15px"></th>
<th class="left" style="padding-right: 15px">22nd+</th>
<th style="padding-right: 15px"></th>
<th class="left" style="padding-right: 15px">1st - 7th</th>
<th style="padding-right: 15px"></th>
<th class="left" style="padding-right: 15px">8th-14th</th>
<th style="padding-right: 15px"></th>
<th class="left" style="padding-right: 15px">15th-21st</th>
<th style="padding-right: 15px"></th>
<th class="left" style="padding-right: 15px">22nd+</th>
<th style="padding-right: 15px"></th>
</tr>
</thead>
</table>
</div>
</div>
其實,我發現了這一切是一個div這是TR的TD內內。如果帶出tr,滾動條就會出現。在tr內部時,無論您是使用div寬度的50%還是100%,這都會簡單地拉伸tr。如果有意義的話,寬度百分比只會減小div的寬度,但不會減小外部tr的寬度。 – Ravi
不同的版本可以在http://jsfiddle.net/rkpolepeddi/d4nc2/3/和http://jsfiddle.net/rkpolepeddi/d4nc2/5/ – Ravi
http://jsfiddle.net/rkpolepeddi/d4nc2/3 /似乎回答你的問題「這怎麼能被阻止,並有一個水平滾動的div?」 – TMS