Dan*_*nny 8 html css html-table fluid
我正在尝试使用HTML和Javascript构建自定义日历,您可以将任务从一天拖放到另一天.我想将第一列和最后两列作为固定宽度并使剩余的列(周一到周五)流畅,以便表总是填满其父级的100%.
我遇到的问题是流体TD根据其中的内容自动调整大小,这意味着当我将任务从一天拖到另一天时,列宽会调整大小.我希望周一到周五的大小完全相同,无论内容如何,并且没有设置文本溢出:隐藏; (因为任务总是需要可见)
即我希望灰色列固定宽度和红色柱流动但彼此均匀,无论其中的内容如何.
编辑:我正在使用jQuery进行拖放功能,因此JavaScript解决方案也可以(尽管不是更好).
HTML:
<table>
<tr>
<th class="row_header">Row Header</th>
<th class="fluid">Mon</th>
<th class="fluid">Tue</th>
<th class="fluid">Wed</th>
<th class="fluid">Thurs</th>
<th class="fluid">Fri</th>
<th class="weekend">Sat</th>
<th class="weekend">Sun</th>
</tr>
<tr>
<td>Before Lunch</td>
<td>This col will be wider than the others because it has lots of content...</td>
<td></td>
<td></td>
<td></td>
<td>But I would really like them to always be the same size!</td>
<td></td>
<td></td>
</tr>
</table>
Run Code Online (Sandbox Code Playgroud)
CSS:
table {
width: 100%;
}
td, th {
border:1px solid black;
}
th {
font-weight:bold;
background:red;
}
.row_header {
width:50px;
background:#ccc;
}
.weekend {
width:100px;
background:#ccc;
}
.fluid {
???
}
Run Code Online (Sandbox Code Playgroud)
kir*_*nvj 10
丹尼,
我想这就是你在寻找的东西.
在这里小提琴http://jsfiddle.net/T6YNK/22/
选中Chrome.
码
<table>
<tr>
<th class="row_header">Row Header</th>
<th class="fluid">Mon</th>
<th class="fluid">Tue</th>
<th class="fluid">Wed</th>
<th class="fluid">Thurs</th>
<th class="fluid">Fri</th>
<th class="weekend">Sat</th>
<th class="weekend">Sun</th>
</tr>
<tr>
<td>Before Lunch</td>
<td>This col will be wider than the others because it has lots of content...</td>
<td></td>
<td></td>
<td></td>
<td>But I would really like them to always be the same size!</td>
<td> </td>
<td> </td>
</tr>
</table>
<style type="text/css">
table {
width: 100%;
}
td, th {
border:1px solid black;
}
th {
font-weight:bold;
background:red;
}
.row_header {
width:50px;
background:#ccc;
}
.weekend {
width:100px;
background:#ccc;
}
td,
th {
overflow:hidden;
}
.fluid {
}
.weekend,
.row_header{
width:50px !important;
}
table{
border: 1px solid black;
table-layout: fixed;
width:100%;
}
</style>?
Run Code Online (Sandbox Code Playgroud)
使用 jQuery(也可以使用常规 JS 来完成,但我更喜欢它来完成此类工作):
(注:我给了表一个ID,这样选择起来会更容易,没有它也可以通过一些修改来完成)
$(function() {
var $my_table = $("#my_table")
,current_width = $my_table.width()
,fluid_columns = $("table .fluid")
,spread_width = (current_width - 150) / fluid_columns.length;
fluid_columns.width(spread_width);
$(window).on("resize", function() {
current_width = $my_table.width();
spread_width = (current_width - 150) / fluid_columns.length;
fluid_columns.width(spread_width);
})
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14731 次 |
| 最近记录: |