多列之后的相同单元格宽度被删除 [英] Equal cell width after multiple columns are removed

查看:100
本文介绍了多列之后的相同单元格宽度被删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新:这里是

  • 你如何制作一个100%宽度的表格,并且列的宽度都是相等的?


  • 表上使用 table-layout:fixed 根据其内容停止浏览器自动调整表的大小。那么你将不得不给每个 TD 一个设置宽度。任何没有设定宽度的 TD s将占用剩余宽度。


    Update: here is a follow up question with colspans.

    I have a table with 8 columns. At runtime, any number of these elements are removed.

    The remaining columns would have equal width. The problem is when the text inside the elements has difference width. Because it seems the browser sets the cell widths based on the length of the text inside each cell. OK, this image probably says it better:

    And here is the code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
    table{
        width:600px;
    }
    table td{
        border:1px solid red;
        text-align:center;
        background-color:#FFFFCC;
    }
    caption{
        color:blue;
        font-size:80%;
    }
    </style>
    <title></title>
    </head>
    <body>
    <table>
        <caption>Original table</caption>
        <tr>
            <td>1</td>
            <td>2</td>
            <td>3</td>
            <td>4</td>
            <td>5</td>
            <td>6</td>
            <td>7</td>
            <td>8</td>
        <tr>
    </table>
    <table>
        <caption>After some columns are removed</caption>
        <tr>
            <td>1</td>
            <td>2</td>
            <td>4</td>
            <td>5</td>
            <td>7</td>
            <td>8</td>
        <tr>
    </table>
    <table>
        <caption>I want these to have the same width</caption>
        <tr>
            <td>1</td>
            <td>Two</td>
            <td>Three</td>
            <td>Column number four</td>
            <td>5</td>
        <tr>
    </table>
    <table>
        <caption>I want these to have the same width, too</caption>
        <tr>
            <td>1</td>
            <td>Column number four</td>
            <td>5</td>
        <tr>
    </table>
    </body>
    </html>
    

    I searched stackoverflow and found the following posts but they are not my answer:

    解决方案

    You can use table-layout:fixed on the table to stop the browser auto resizing the table depending on its contents. Then you will have to give each TD a set width. Any TDs without a set width will take up the remaining width.

    这篇关于多列之后的相同单元格宽度被删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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