HTML Table - Both fixed and multiple variable column widths

后端 未结 3 2143
我寻月下人不归
我寻月下人不归 2021-02-12 15:47

I have to build a table with 5 columns. The table width is variable (50% of content width). Some columns contain fixed-size buttons, so those columns should have a fixed with, s

3条回答
  •  情书的邮戳
    2021-02-12 16:34

    You could set the table-layout: fixed for the table element, then simply set width attribute on relevant or elements:

    table {
        table-layout: fixed;
    }
    

    JSFiddle Demo.

    From the MDN:

    The table-layout CSS property defines the algorithm to be used to layout the table cells, rows, and columns.

    Values:

    fixed:
    Table and column widths are set by the widths of table and col elements or by the width of the first row of cells. Cells in subsequent rows do not affect column widths.

提交回复
热议问题