【问题标题】:How to Modify the Font Size of the Contents in a Table如何修改表格内容的字体大小
【发布时间】:2023-03-21 04:49:02
【问题描述】:

在我的表格中,我正在尝试更改字体大小。我尝试在标签中添加字体大小,将其添加到 Myposts 类的 CSS 代码中,但没有任何效果。如何更改字体大小?

  <table width="100%" border="0" class = "Myposts"; align="center" cellpadding="3" cellspacing="1"  bgcolor="#686868 " >
  <tr>
   <td width="6%" align="center" bgcolor="#505050 " ><strong>#</strong></td>
   <td width="53%" align="center" bgcolor="#505050 "><strong>Job Description</strong></td>
   <td width="15%" align="center" bgcolor="#505050 "><strong>Views</strong></td>
   <td width="13%" align="center" bgcolor="#505050 "><strong>Replies</strong></td>
   <td width="13%" align="center" bgcolor="#505050 "><strong>Date/Time</strong></td>
  </tr>

【问题讨论】:

    标签: php html css fonts html-table


    【解决方案1】:

    您可以在 CSS 中选择表格单元格

    table.Myposts tr td {
     font-size: 18px;
    }
    

    【讨论】:

      【解决方案2】:
      .Myposts td {
        font-size: 20px;
      }
      

      jsfiddle 中的示例:http://jsfiddle.net/Wk28Y/

      【讨论】:

      • 哦,所以你必须指定td?现在明白了!太感谢了!这就是我没有得到结果的原因。
      【解决方案3】:

      请不要认为这是一个答案,只是考虑问题的不同方式。 FIDDLE

      您可以通过将第一行设为&lt;th&gt; 而不是&lt;td&gt; 来摆脱“粗体”行。

      将 css 表格样式添加到您的 Myposts 类。

      您在标题中注意到它是 php,但我没有看到任何 php 标签。所以我假设您将 php 传递给 html 页面,因此 css 样式仍然适用于您。

      HTML

      <table class = "Myposts">
        <tr>
          <td>#</td>
          <td>Job Description</td>
          <td>Views</td>
          <td>Replies</td>
          <td>Date/Time</td>
        </tr>
      </table>
      

      CSS

      table {
        width: 100%;
        border: 0px solid black;
        background-color: #686868;
        border-spacing: 1px;
      }
      table td {
        background-color: #505050;
        color: white;
        text-align: center;
        font-weight: bold;
        padding: 3px;
        font-size: 20px;
      }
      table tr td:nth-child(1) {
        width: 6%;
      }
      table tr td:nth-child(2) {
        width: 53%;
      }
      table tr td:nth-child(3) {
        width: 15%;
      }
      table tr td:nth-child(4) {
        width: 13%;
      }
      table tr td:nth-child(5) {
        width: 13%;
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-08
        • 2011-09-25
        • 1970-01-01
        • 2021-04-26
        相关资源
        最近更新 更多