带有 3 列的表.固定中心列宽度.如何在其他两列上共享宽度? [英] Table with 3 columns. Fixed center column width. How to have shared width on other two columns?

查看:19
本文介绍了带有 3 列的表.固定中心列宽度.如何在其他两列上共享宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 100% 宽度的表格,有 3 列.中心列的宽度必须为 600 像素.如何在用完剩余空间的同时让另外两个宽度相等?

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?

<table style="width: 100%">
    <tr>
        <td>left</td>
        <td style="width: 600px">center</td>
        <td>right</td>
    </tr>
</table>

目前,根据左列或右列的内容,它们总是不均匀的.我试过在左侧和右侧设置 50% 的宽度以及其他数字和最小宽度试验.

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.

请不要使用 jQuery/Javascript.

Please no jQuery/Javascript.

推荐答案

这个老问题的新答案.

  1. 给中间列 th 一个 max-widthmin-width 而不是 width
  2. 给左右th一个width50%.
  3. 完全不要给table一个width.
  1. Give the middle column th a max-width and min-width instead of width
  2. Give the left and right th a width of 50%.
  3. Don't give the table a width at all.

我已将此示例中间列 width 固定在 300px.

I have fixed this examples middle column width at 300px.

jsBin 示例!

CSS

table {
    border-collapse: collapse;
}
th, td {
    border: solid 1px #CCC;
    padding: 10px;
}
.fixed {
    max-width: 300px;
    min-width: 300px;
}
.fluid {
        width: 50%;
}

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>

这篇关于带有 3 列的表.固定中心列宽度.如何在其他两列上共享宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆