什么取代了HTML5表格中的cellpadding,cellspacing,valign和align?

    技术2022-08-01  79

    本文翻译自:What replaces cellpadding, cellspacing, valign, and align in HTML5 tables?

    In Visual Studio , I'm seeing these warnings: 在Visual Studio中 ,我看到这些警告:

    Validation (HTML 5): Attribute 'cellpadding' is not a valid attribute of element 'table'. 验证(HTML 5):属性“cellpadding”不是元素“table”的有效属性。 Validation (HTML 5): Attribute 'cellspacing' is not a valid attribute of element 'table'. 验证(HTML 5):属性'cellspacing'不是元素'table'的有效属性。 Validation (HTML 5): Attribute 'valign' is not a valid attribute of element 'td'. 验证(HTML 5):属性'valign'不是元素'td'的有效属性。 Validation (HTML 5): Attribute 'align' is not a valid attribute of element 'td'. 验证(HTML 5):属性'align'不是元素'td'的有效属性。

    If they are not valid attributes in HTML5 , what replaces them in CSS? 如果它们不是HTML5中的有效属性,那么在CSS中替换它们的是什么?


    #1楼

    参考:https://stackoom.com/question/PNb7/什么取代了HTML-表格中的cellpadding-cellspacing-valign和align


    #2楼

    This should solve your problem: 这应该可以解决您的问题:

    td { /* <http://www.w3.org/wiki/CSS/Properties/text-align> * left, right, center, justify, inherit */ text-align: center; /* <http://www.w3.org/wiki/CSS/Properties/vertical-align> * baseline, sub, super, top, text-top, middle, * bottom, text-bottom, length, or a value in percentage */ vertical-align: top; }

    #3楼

    Alternatively, can use for particular table 或者,可以用于特定的表

    <table style="width:1000px; height:100px;"> <tr> <td align="center" valign="top">Text</td> //Remove it <td class="tableFormatter">Text></td> </tr> </table>

    Add this css in external file 在外部文件中添加此css

    .tableFormatter { width:100%; vertical-align:top; text-align:center; }

    #4楼

    On particular table 在特定的桌子上

    <table style="border-collapse: separate; border-spacing: 10px;" > <tr> <td>Hi</td> <td>Hello</td> <tr/> <tr> <td>Hola</td> <td>Oi!</td> <tr/> </table>


    #5楼

    I think you are using Visual Studio to edit web page. 我认为您正在使用Visual Studio编辑网页。 Then I also faced the same issue. 然后我也遇到了同样的问题。 The thing is, there is no such 'attribute' for this element. 问题是,这个元素没有这样的'属性'。

    You have you move this attribute to style: 您已将此属性移动到样式:

    From: 从:

    <td valign="top">XXXX</td>

    To: 至:

    <td style="vertical-align:top;">XXXX</td>

    #6楼

    /* cellpadding */ th, td { padding: 5px; } /* cellspacing */ table { border-collapse: separate; border-spacing: 5px; } /* cellspacing="5" */ table { border-collapse: collapse; border-spacing: 0; } /* cellspacing="0" */ /* valign */ th, td { vertical-align: top; } /* align (center) */ table { margin: 0 auto; }
    Processed: 0.011, SQL: 9