Html 使用 CSS 格式化表格中的文本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9135315/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-28 22:17:04  来源:igfitidea点击:

Formatting the text in a table with CSS

htmlcsshtml-table

提问by Chris

I need some basic css help. I attempted to style the cells of a table using a css stylesheet, but its not working

我需要一些基本的 css 帮助。我尝试使用 css 样式表设置表格单元格的样式,但它不起作用

The code of the table is:

表的代码是:

<table> 
<tr><td><p style="font-size:13px"><a href="mailto:[email protected]">XXX&nbsp;&nbsp;&nbsp;</a></p></td><td><p style="font-size:13px">XXXX&nbsp;&nbsp;&nbsp;</p></td><td><p style="font-size:13px">XXXXXXX   </p></td></tr> 
   <tr><td><p style="font-size:13px"><a href="mailto:[email protected]">XXX&nbsp;&nbsp;&nbsp;</a></p></td><td><p style="font-size:13px">XXXX&nbsp;&nbsp;&nbsp;</p></td><td><p style="font-size:13px">XXXXXXX   </p></td></tr> 
    <tr><td><p style="font-size:13px"><a href="mailto:[email protected]">XXX&nbsp;&nbsp;&nbsp;</a></p></td><td><p style="font-size:13px">XXXX&nbsp;&nbsp;&nbsp;</p></td><td><p style="font-size:13px">XXXXXXX   </p></td></tr> 
     <tr><td><p style="font-size:13px"><a href="mailto:[email protected]">XXX&nbsp;&nbsp;&nbsp;</a></p></td><td><p style="font-size:13px">XXXX&nbsp;&nbsp;&nbsp;</p></td><td><p style="font-size:13px">XXXXXXX   </p></td></tr> 
      <tr><td><p style="font-size:13px"><a href="mailto:[email protected]">XXX&nbsp;&nbsp;&nbsp;</a></p></td><td><p style="font-size:13px">XXXX&nbsp;&nbsp;&nbsp;</p></td><td><p style="font-size:13px">XXXXXXX   </p></td></tr> 
       <tr><td><p style="font-size:13px"><a href="mailto:[email protected]">XXX&nbsp;&nbsp;&nbsp;</a></p></td><td><p style="font-size:13px">XXXX&nbsp;&nbsp;&nbsp;</p></td><td><p style="font-size:13px">XXXXXXX   </p></td></tr> 
        <tr><td><p style="font-size:13px"><a href="mailto:[email protected]">XXX&nbsp;&nbsp;&nbsp;</a></p></td><td><p style="font-size:13px">XXXX&nbsp;&nbsp;&nbsp;</p></td><td><p style="font-size:13px">XXXXXXX   </p></td></tr> 
         <tr><td><p style="font-size:13px"><a href="mailto:[email protected]">XXX&nbsp;&nbsp;&nbsp;</a></p></td><td><p style="font-size:13px">XXXX&nbsp;&nbsp;&nbsp;</p></td><td><p style="font-size:13px">XXXXXXX   </p></td></tr> 
                  </table>

The only way I got the text to not go to browser defaults was to explicitly state it on every single cell, which seems like a waste of load time (as miniscule as it is). Is there a way to set the size of the text for the entire table? It's is all the same size.

我让文本不进入浏览器默认值的唯一方法是在每个单元格上明确说明它,这似乎是在浪费加载时间(尽管如此微不足道)。有没有办法设置整个表格的文本大小?都是一样的大小。

I tried putting the table inside a <p>and then styling it using a CSS class, but it was not working. Not sure if it matters, but I am using XHTML 1.0.

我尝试将表格放在 a 中<p>,然后使用 CSS 类对其进行样式设置,但它不起作用。不确定它是否重要,但我使用的是 XHTML 1.0。

回答by

I would add the class to the table:

我会将该类添加到表中:

<table class='myFormat'><tr>....</tr></table>

Then:

然后:

table.myFormat tr td { font-size: 13px; }

Can you tell me what browsers this is in?

你能告诉我这是什么浏览器吗?

回答by Kummer Wolfe

Have you tried:

你有没有尝试过:

td { font-size: 13px }

OR

或者

td.myfontsize { font-size: 13px ; }

then using:

然后使用:

class="myfontsize" 

applied to your td tags?

应用于您的 td 标签?

回答by ZyteX

Change <table>to <table style="font-size: 13px;">. That should change all of the text inside of the table.

更改<table><table style="font-size: 13px;">。这应该会更改表格内的所有文本。

Otherwise, you can just add a class or id to it and use it to style the rows as said by @user1086498.

否则,您只需向其中添加一个类或 id,并使用它来设置行的样式,如@user1086498 所述。