HTML table colgroup element not working?

后端 未结 7 2184
无人及你
无人及你 2021-01-03 18:25

I want different styles on each column of a table. I\'ve read that you could do that by using or , but I had no luck. I

7条回答
  •  攒了一身酷
    2021-01-03 18:50

    In 2020, if you want different styles on columns, you can:
    1. style/CSS , but for only a few properties
    2. use th/td:nth-child(#number) in CSS (my preferred solution, no idea about what happens with colspans)
    3. manually add a class to the th/td elements

    References:
    https://developer.mozilla.org/en-US/docs/Web/HTML/Element/col
    https://www.w3.org/TR/CSS22/tables.html#columns

    You're not supposed to use the "width" HTML attribute, instead use style/CSS. In the style/CSS for you're supposed to use only "border", "background", "width" and "visibility". You can use ems to express values.

    I'm confused: w3 says "The 'width' property gives the minimum width for the column." which looks contradictory to me, given the existence of a "min-width" property. On Firefox 72 (Ubuntu)

    
    

    sets a "fixed" width (as I expected). If I resize the window, narrowing it, the column is resized and the content is wrapped into more lines.

提交回复
热议问题