什么是 <col width="0*"> 的 CSS 替代品?

  • 本文关键字:CSS 替代品 col width css
  • 更新时间 :
  • 英文 :


考虑以下HTML片段:

<!DOCTYPE html>
<title>Table</title>
<meta charset="utf-8">
<table border="1" style="width: 800px;">
    <col width="0*">
    <col>
    <col width="0*">
    <tr>
        <td><div style="background: red; width: 100px; height: 100px;"></div></td>
        <td><div style="background: blue; color: white; text-align: center;">hello world</div></td>
        <td><div style="background: green; width: 50px; height: 50px;"></div></td>
    </tr>
</table>

如何用CSS替换<col width="0*">

根据您的示例,您希望仅将CSS应用于第一列和最后一列。因此,只需在列中添加一个可重用的CSS类名,并为其定义样式

<col class="columnStyle">
<col>
<col  class="columnStyle">

在您的CSS文件中:

col.columnStyle {
    width: 0px;
    /* specify required width here */
}

这将只将特定宽度应用于那些列,而不应用于中间的列。

最新更新