在 HTML 表格中指定字体和大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41367955/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Specifying Font and Size in HTML table
提问by Neil Weicher
I am trying to specify the Font Face and Size for text in a table. It seems to respect the FACE= but ignores the SIZE=. For example, I have the HTML shown below. It correctly displays the text in Courier New, but both tables display with the same font size. Any clue what I am doing wrong?
我正在尝试为表格中的文本指定字体和大小。它似乎尊重 FACE= 但忽略了 SIZE=。例如,我有如下所示的 HTML。它在 Courier New 中正确显示文本,但两个表都以相同的字体大小显示。任何线索我做错了什么?
<font face="Courier New" size="12"><table width="100%"><tr><td><b>Client</b></td><td><b>InstanceName</b></td><td><b>dbname</b></td><td><b>Filename</b></td><td><b>KeyName</b></td><td><b>Rotation</b></td><td><b>Path</b></td></tr>
<tr><td>NEWDEV6</td><td>EXPRESS2012</td><td>master</td><td>master.mdf</td><td>test_key_16</td><td>0</td><td>d:\Program Files\Microsoft SQL Server\MSSQL11.EXPRESS2012\MSSQL\DATA\master.mdf</td></tr>
</table></font>
<font face="Courier New" size="24"><table width="100%"><tr><td><b>Client</b></td><td><b>InstanceName</b></td><td><b>dbname</b></td><td><b>Filename</b></td><td><b>KeyName</b></td><td><b>Rotation</b></td><td><b>Path</b></td></tr>
<tr><td>NEWDEV6</td><td>EXPRESS2012</td><td>master</td><td>master.mdf</td><td>test_key_16</td><td>0</td><td>d:\Program Files\Microsoft SQL Server\MSSQL11.EXPRESS2012\MSSQL\DATA\master.mdf</td></tr>
</table></font>
回答by LexieHankins
First, try omitting the quotes from 12 and 24. Worth a shot.
首先,尝试省略 12 和 24 中的引号。值得一试。
Second, it's better to do this in CSS. See also http://www.w3schools.com/css/css_font.asp. Here is an inline style for a table tag:
其次,最好在 CSS 中执行此操作。另见http://www.w3schools.com/css/css_font.asp。这是表格标签的内联样式:
<table style='font-family:"Courier New", Courier, monospace; font-size:80%' ...>...</table>
Better still, use an external style sheet ora style tag near the top of your HTML document. See also http://www.w3schools.com/css/css_howto.asp.
更好的是,在 HTML 文档顶部附近使用外部样式表或样式标记。另见http://www.w3schools.com/css/css_howto.asp。
回答by Jocimar Candido
Enclose your code with the html and body tags. Size attribute does not correspond to font-size and it looks like its domain does not go beyond value 7. Furthermore font tag is not supported in HTML5. Consider this code for your case
用 html 和 body 标签将您的代码括起来。Size 属性与 font-size 不对应,看起来它的域没有超过值 7。此外,HTML5 不支持 font 标签。为您的案例考虑此代码
<!DOCTYPE html>
<html>
<body>
<font size="2" face="Courier New" >
<table width="100%">
<tr>
<td><b>Client</b></td>
<td><b>InstanceName</b></td>
<td><b>dbname</b></td>
<td><b>Filename</b></td>
<td><b>KeyName</b></td>
<td><b>Rotation</b></td>
<td><b>Path</b></td>
</tr>
<tr>
<td>NEWDEV6</td>
<td>EXPRESS2012</td>
<td>master</td><td>master.mdf</td>
<td>test_key_16</td><td>0</td>
<td>d:\Program Files\Microsoft SQL Server\MSSQL11.EXPRESS2012\MSSQL\DATA\master.mdf</td>
</tr>
</table>
</font>
<font size="5" face="Courier New" >
<table width="100%">
<tr>
<td><b>Client</b></td>
<td><b>InstanceName</b></td>
<td><b>dbname</b></td>
<td><b>Filename</b></td>
<td><b>KeyName</b></td>
<td><b>Rotation</b></td>
<td><b>Path</b></td></tr>
<tr>
<td>NEWDEV6</td>
<td>EXPRESS2012</td>
<td>master</td>
<td>master.mdf</td>
<td>test_key_16</td>
<td>0</td>
<td>d:\Program Files\Microsoft SQL Server\MSSQL11.EXPRESS2012\MSSQL\DATA\master.mdf</td></tr>
</table></font>
</body>
</html>
回答by trevor
The font taghas been deprecated for some time now.
该字体标签已被弃用了一段时间。
That being said, the reason why both of your tables display with the same font size is that the 'size' attribute only accepts values ranging from 1 - 7. The smallest size is 1. The largest size is 7. The default size is 3. Any values larger than 7 will just display the same as if you had used 7, because 7 is the maximum value allowed.
话虽如此,您的两个表格显示相同字体大小的原因是“大小”属性仅接受 1 - 7 范围内的值。最小大小为 1。最大大小为 7。默认大小为 3 . 任何大于 7 的值都将显示与使用 7 相同的值,因为 7 是允许的最大值。
And as @Alex H said, you should be using CSS for this.
正如@Alex H 所说,您应该为此使用 CSS。
回答by Anthony
This worked for me and also worked with bootstrap tables
这对我有用,也适用于引导表
<style>
.table td, .table th {
font-size: 10px;
}
</style>