i have a 100% width table with 3 columns. The center column must be 600px width. How can I have the other two equal width while using up the remaining space?
我有一个100%宽度的表,有3列。中心列的宽度必须为600px。如何在占用剩余空间的同时使另外两个宽度相等?
<table style="width: 100%">
<tr>
<td>left</td>
<td style="width: 600px">center</td>
<td>right</td>
</tr>
</table>
Currently, depending on the content of left or right columns, they are always uneven. I have tried setting 50% width on the left and right as well as other numbers and min-width trials.
目前,根据左列或右列的内容,它们总是不均匀的。我尝试在左右两侧设置50%的宽度以及其他数字和最小宽度试验。
Please no jquery/javascript. Thank you
请不要jquery / javascript。谢谢
3 个解决方案
#1
4
New answer to this old question.
这个老问题的新答案。
- Give the middle column
th
amax-width
andmin-width
instead ofwidth
- 给中间列一个最大宽度和最小宽度而不是宽度
- Give the left and right
th
awidth
of50%
. - 给左右宽度为50%。
- Don't give the
table
awidth
at all. - 不要给桌子宽度。
I have fixed this examples middle column width
at 300px
.
我已将此示例中间列宽修复为300px。
jsBin示例!
CSS
CSS
table {
border-collapse: collapse;
}
th, td {
border: solid 1px #CCC;
padding: 10px;
}
.fixed {
max-width: 300px;
min-width: 300px;
}
.fluid {
width: 50%;
}
HTML
HTML
<table>
<thead>
<tr>
<th class="fluid">First Column</th>
<th class="fixed">Fixed Column</th>
<th class="fluid">Third Column</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
#2
0
The use of "colgroup" tag could be a great help for this.
使用“colgroup”标签可能对此有很大帮助。
<table class="fixed-center-table" border="1">
<thead>
<colgroup>
<col>
<col id="middle-column">
<col>
</colgroup>
<tr>
<th>First Column</th>
<th></th>
<th>Third Column</th>
</tr>
</thead>
<tbody>
<tr>
<td>AAAAAA</td>
<td>BBBB</td>
<td>CCCCC</td>
</tr>
<tr>
<td>AAAAAA</td>
<td>BBBB</td>
<td>CCCCC</td>
</tr>
<tr>
<td>AAAAAA</td>
<td>BBBB</td>
<td>CCCCC</td>
</tr>
</tbody>
</table>
.fixed-center-table {
table-layout: fixed;
width: 100%;
border-collapse: collapse;
}
.fixed-center-table td{
text-align: center;
}
col#middle-column {
width: 600px;
}
#3
-2
I guess "align=center" used with center column may help you.
我猜中心列使用的“align = center”可能会对你有所帮助。
#1
4
New answer to this old question.
这个老问题的新答案。
- Give the middle column
th
amax-width
andmin-width
instead ofwidth
- 给中间列一个最大宽度和最小宽度而不是宽度
- Give the left and right
th
awidth
of50%
. - 给左右宽度为50%。
- Don't give the
table
awidth
at all. - 不要给桌子宽度。
I have fixed this examples middle column width
at 300px
.
我已将此示例中间列宽修复为300px。
jsBin示例!
CSS
CSS
table {
border-collapse: collapse;
}
th, td {
border: solid 1px #CCC;
padding: 10px;
}
.fixed {
max-width: 300px;
min-width: 300px;
}
.fluid {
width: 50%;
}
HTML
HTML
<table>
<thead>
<tr>
<th class="fluid">First Column</th>
<th class="fixed">Fixed Column</th>
<th class="fluid">Third Column</th>
</tr>
</thead>
<tbody>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
#2
0
The use of "colgroup" tag could be a great help for this.
使用“colgroup”标签可能对此有很大帮助。
<table class="fixed-center-table" border="1">
<thead>
<colgroup>
<col>
<col id="middle-column">
<col>
</colgroup>
<tr>
<th>First Column</th>
<th></th>
<th>Third Column</th>
</tr>
</thead>
<tbody>
<tr>
<td>AAAAAA</td>
<td>BBBB</td>
<td>CCCCC</td>
</tr>
<tr>
<td>AAAAAA</td>
<td>BBBB</td>
<td>CCCCC</td>
</tr>
<tr>
<td>AAAAAA</td>
<td>BBBB</td>
<td>CCCCC</td>
</tr>
</tbody>
</table>
.fixed-center-table {
table-layout: fixed;
width: 100%;
border-collapse: collapse;
}
.fixed-center-table td{
text-align: center;
}
col#middle-column {
width: 600px;
}
#3
-2
I guess "align=center" used with center column may help you.
我猜中心列使用的“align = center”可能会对你有所帮助。