Width confusion after table plus cospan

paste the code directly, the requirement is very simple, the width of three columns is specified, and the content beyond part shows . . When there is no more cospan header column, there is no problem, and after that, the width is evenly distributed.

<!DOCTYPE html>
<html lang="zh-ch">

<head>
    <meta charset="UTF-8">
    <title>Table | Test</title>
    <style type="text/css">
    table.gridtable {
        width: 352px;
        font-family: verdana, arial, sans-serif;
        font-size: 12px;
        color: -sharp333333;
        border-width: 1px;
        border-color: -sharp666666;
        border-collapse: collapse;
        table-layout: fixed;
    }

    table.gridtable td {
        /*width: 100px;*/
        padding: 8px;
        border-width: 1px;
        border-style: solid;
        border-color: -sharp666666;
        background-color: -sharpffffff;
        word-break: break-all;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    td.td-width-50 {
        width: 50px;
    }

    td.td-width-100 {
        width: 100px;
    }

    td.td-width-150 {
        width: 150px;
    }
    </style>
</head>

<body>
    <table class="gridtable">
        <!-- cospan -->
        <tr>
            <td colspan="2">Info Header 1</td>
            <td>Info Header 2</td>
        </tr>
        <tr>
            <td class="td-width-50" title="Text 1A">Text 1A</td>
            <td class="td-width-100">Text 1B</td>
            <td class="td-width-150">Text 1C</td>
        </tr>
        <tr>
            <td class="td-width-50">Text 2B</td>
            <td class="td-width-100">Text 2B</td>
            <td class="td-width-150">Text 2C</td>
        </tr>
    </table>
</body>

</html>
Mar.09,2021

=-= two class with td-width-150 on the first line will do. Analyze it so that it is the fastest


The

table does not specify a width to solve this problem. The width of
More, td can solve two problems by adding min-width and max-width:

  1. td content burst cell width
  2. Cell width shrinks automatically when container width is not enough

the final code is as follows:

<!DOCTYPE html>
<html lang="zh-ch">

<head>
    <meta charset="UTF-8">
    <title>Table | Test</title>
    <style type="text/css">
    table.gridtable {
        font-family: verdana, arial, sans-serif;
        font-size: 12px;
        color: -sharp333333;
        border-width: 1px;
        border-color: -sharp666666;
        border-collapse: collapse;
        table-layout: fixed;
    }

    table.gridtable td {
        padding: 8px;
        border-width: 1px;
        border-style: solid;
        border-color: -sharp666666;
        background-color: -sharpffffff;
        word-break: break-all;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    td.td-width-50 {
        width: 50px;
        min-width: 50px;
        max-width: 50px;
    }

    td.td-width-100 {
        width: 100px;
        min-width: 100px;
        max-width: 100px;
    }

    td.td-width-150 {
        width: 150px;
        min-width: 150px;
        max-width: 150px;
    }
    </style>
</head>

<body>
    <table class="gridtable">
        <!-- cospan -->
        <tr>
            <td colspan="2">Info Header 1</td>
            <td>Info Header 2</td>
        </tr>
        <tr>
            <td class="td-width-50" title="Text 1A">Text 1A</td>
            <td class="td-width-100">Text 1B</td>
            <td class="td-width-150">Text 1C</td>
        </tr>
        <tr>
            <td class="td-width-50" title="Text 2BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB">Text 2BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB</td>
            <td class="td-width-100">Text 2B</td>
            <td class="td-width-100">Text 2C</td>
        </tr>
    </table>
</body>

</html>
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3ed10-2bc98.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3ed10-2bc98.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?