CSS Cell Margin

后端 未结 16 1276
长情又很酷
长情又很酷 2020-11-29 02:18

In my HTML document, I have a table with two columns and multiple rows. How can I increase the space in between the first and second column with css? I\'ve tried applying \"

16条回答
  •  一整个雨季
    2020-11-29 03:05

    This solution work for td's that need both border and padding for styling.
    (Tested on Chrome 32, IE 11, Firefox 25)

    CSS:
    table {border-collapse: separate; border-spacing:0; }   /*  separate needed      */
    td { display: inline-block; width: 33% }  /*  Firefox need inline-block + width  */
    td { position: relative }                 /*  needed to make td move             */
    td { left: 10px; }                        /*  push all 10px                      */
    td:first-child { left: 0px; }             /*  move back first 10px               */
    td:nth-child(3) { left: 20px; }           /*  push 3:rd another extra 10px       */
    
    /*  to support older browsers we need a class on the td's we want to push
        td.col1 { left: 0px; }
        td.col2 { left: 10px; }
        td.col3 { left: 20px; }
    */
    
    HTML:
    
    Player Result Average

    Updated 2016

    Firefox now support it without inline-block and a set width

    table {border-collapse: separate; border-spacing:0; }
    td { position: relative; padding: 5px; }
    td { left: 10px; }
    td:first-child { left: 0px; }
    td:nth-child(3) { left: 20px; }
    td { border: 1px solid gray; }
    
    
    /* CSS table */
    .table {display: table; }
    .tr { display: table-row; }
    .td { display: table-cell; }
    
    .table { border-collapse: separate; border-spacing:0; }
    .td { position: relative; padding: 5px; }
    .td { left: 10px; }
    .td:first-child { left: 0px; }
    .td:nth-child(3) { left: 20px; }
    .td { border: 1px solid gray; }
    Player Result Average
    Player
    Result
    Average

提交回复
热议问题