带有等宽字体列的 html 表

Mic*_*ael 1 html css fonts

我正在尝试使用 css 创建一个 html 表。第一列是等宽字体,因为它包含计算机代码。

但是, font-family 属性似乎不起作用。这是 html 文件:

<html>    
<head>
<link rel="stylesheet" href="styles.css">
</head>    
<body>    
<table cellspacing="0" class="software">
<COLGROUP class="command">
<COLGROUP>
<tr>
  <td>command 1</td>
  <td>description</td>
</tr>
<tr>
  <td>command 2</td>
  <td>description</td>
</tr>
</table>    
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

对应的css文件包含以下内容:

table.software{
    font-family: Arial;
    font-size: 13pt;
    border-width: 1px 1px 1px 1px;
    border-style: solid;
}    
table.software td{
    text-align: left;
    border-width: 1px 1px 1px 1px;
    border-style: solid;
    padding: 5px;
}    
.command{
    font-family: monospace;
    font-size: 10pt;
    width: 300;
}
Run Code Online (Sandbox Code Playgroud)

我将非常感谢如何实现字体更改的指针。谢谢!

问候,迈克尔

Ric*_*ock 5

COLCOLGROUP支持有限数量的 CSS 样式。

您可以改用nth-child(x)CSS3 选择器,其中x是要设置样式的列数(第一列为 1):

table.software{
    font-family: Arial;
    font-size: 13pt;
    border-width: 1px 1px 1px 1px;
    border-style: solid;
}    

table.software td {
    text-align: left;
    border-width: 1px 1px 1px 1px;
    border-style: solid;
    padding: 5px;
}    

table.software td:nth-child(1) {
    font-family: monospace;
    font-size: 10pt;
    width: 300;
}
Run Code Online (Sandbox Code Playgroud)
<table cellspacing="0" class="software">
<tr>
  <td>command 1</td>
  <td>description</td>
</tr>
<tr>
  <td>command 2</td>
  <td>description</td>
</tr>
</table>  
Run Code Online (Sandbox Code Playgroud)