How to get table cells evenly spaced?

前端 未结 8 1928
长发绾君心
长发绾君心 2020-12-09 15:01

I\'m trying to create a page with a number of static html tables on them.

What do I need to do to get them to display each column the same size as each other column

8条回答
  •  温柔的废话
    2020-12-09 15:17

    You can use CSS. One way is to set table-layout to fixed, which stops the table and it's children from sizing according to their content. You can then set a fixed width on the relevant td elements. This should do the trick:

    table.PerformanceTable {
        table-layout: fixed;
        width: 500px;
    }
        table.PerformanceTable td.PerformanceCell {
            width: 75px;
        }
    

    Suggestions for for tidying up? You don't need the cellpadding or cellspacing attributes, or the TableRow and TableHeader classes. You can cover those off in CSS:

    table {
        /* cellspacing */
        border-collapse: collapse;
        border-spacing: 0;
    }
    th {
        /* This covers the th elements */
    }
    tr {
        /* This covers the tr elements */
    }
    th, td {
        /* cellpadding */
        padding: 0;
    }
    

    You should use a heading (e.g.

    ) instead of and a

    or a table instead of the Source . You wouldn't need the
    elements either, because you'd be using proper block level elements.

提交回复
热议问题