Style the first column of a table differently

后端 未结 5 722
清歌不尽
清歌不尽 2020-12-25 09:19

If I have a table with two columns, how do I specify a padding or any other css so that it is applied just for the first column of

5条回答
  •  情深已故
    2020-12-25 10:01

    If you've to support IE7, a more compatible solution is:

    /* only the cells with no cell before (aka the first one) */
    td {
        padding-left: 20px;
    }
    /* only the cells with at least one cell before (aka all except the first one) */
    td + td {
        padding-left: 0;
    }
    

    Also works fine with li; general sibling selector ~ may be more suitable with mixed elements like a heading h1 followed by paragraphs AND a subheading and then again other paragraphs.

提交回复
热议问题