Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在HTML5表格中,什么替代了cellpadding、cellspacing、valign和align?_Html_Css_Visual Studio_Css Tables - Fatal编程技术网

在HTML5表格中,什么替代了cellpadding、cellspacing、valign和align?

在HTML5表格中,什么替代了cellpadding、cellspacing、valign和align?,html,css,visual-studio,css-tables,Html,Css,Visual Studio,Css Tables,在Visual Studio中,我看到以下警告: 验证(HTML 5):属性“cellpadding”不是元素“table”的有效属性 验证(HTML 5):属性“cellspacing”不是元素“table”的有效属性 验证(HTML 5):属性“valign”不是元素“td”的有效属性 验证(HTML 5):属性“align”不是元素“td”的有效属性 如果它们不是HTML5中的有效属性,那么在CSS中用什么替换它们呢?这应该可以解决您的问题: /* cellpadding */ th,

在Visual Studio中,我看到以下警告:

  • 验证(HTML 5):属性“cellpadding”不是元素“table”的有效属性
  • 验证(HTML 5):属性“cellspacing”不是元素“table”的有效属性
  • 验证(HTML 5):属性“valign”不是元素“td”的有效属性
  • 验证(HTML 5):属性“align”不是元素“td”的有效属性

如果它们不是HTML5中的有效属性,那么在CSS中用什么替换它们呢?

这应该可以解决您的问题:

/* 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; }
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;
}
td{
/* 
*左、右、居中、对齐、继承
*/
文本对齐:居中;
/* 
*基线、子、超级、顶部、文本顶部、中间、,
*底部、文本底部、长度或百分比值
*/
垂直对齐:顶部;
}

或者,可以用于特定的表

 <table style="width:1000px; height:100px;">
    <tr>
        <td align="center" valign="top">Text</td> //Remove it
        <td class="tableFormatter">Text></td>
    </tr>
</table>
在特定的桌子上

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

你好
你好
赫拉
氧指数!

值得注意的是,边框间距似乎只有在表上使用此属性时才起作用。“border collapse:separate;”@Samir——似乎是
float:right将完成此操作。仅供参考:从仅供参考:不建议从内联css移动。是的,你是对的。我不推荐。我们使用外部css文件。ClassName{width:100%;text align:center;vertical align:top;}Thanks我发现即使使用HTML5,cellpadding和cellspacing属性仍然是必需的。也就是说,在不显式声明这些属性的情况下,将应用默认的填充和间距。因此,我发现必须始终将它们设置为值“0”,以便使默认值为零。它们可能已经被弃用,但浏览器还没有开始使用它们。默认值仍应用于Chrome版本37。