CSS改变td大小

时间:2015-09-24 11:06:54

标签: html css

我正在尝试创建一个漂亮的桌子。我找到了一个模板,我想修改它。问题是,如果我想修改顶部标题的字体大小,那么“head_nav”中的标题就像这样:#head_nav th{ font-size: 30px;}没有任何反应。难道我做错了什么?另外我想让数据“TD”成为正方形,而不是矩形,所以我尝试了这个:tr, td{ width: 100%; height:100%;}但是没有任何反应。

这是我的代码:

<!doctype html>
<html>
<head>
    <title>Timetable</title>
    <style type="text/css">
    body
    {
        font-family: arial;
    }

    th,td
    {
        margin: 0;
        text-align: center;
        border-collapse: collapse;
        outline: 1px solid #e3e3e3;
    }

    td
    {
        padding: 5px 10px;
    }

    th
    {
        background: #666;
        color: white;
        padding: 5px 10px;
    }

    td:hover
    {
        cursor: pointer;
        background: #666;
        color: white;
    }
    </style>

</head>

<body>
    <table width="80%" align="center" >
    <div id="head_nav">
    <tr>
        <th>Time</th>
        <th>Monday</th>
        <th>Tuesday</th>
        <th>Wednesday</th>
        <th>Thrusday</th>
        <th>Friday</th>
        <th>Saturday</th>
    </tr>
    </div>  
    
        <tr>
            <th>10:00 - 11:00</th>
            
                <td>Physics-1</td>
                <td>English</td>
                <td title="No Class" class="Holiday"></td>
                <td>Chemestry-1</td>
                <td>Alzebra</td>
                <td>Physical</td>
            </div>
        </tr>
    
        <tr>
            <th>11:00 - 12:00</td>
            
                <td>Math-2</td>
                <td>Chemestry-2</td>
                <td>Physics-1</td>
                <td>Hindi</td>
                <td>English</td>
                <td>Soft Skill</td>
            </div>
        </tr>
    
        <tr>
            <th>12:00 - 01:00</td>
            
                <td>Hindi</td>
                <td>English</td>
                <td>Math-1</td>
                <td>Chemistry</td>
                <td>Physics</td>
                <td>Chem.Lab</td>
    
            </div>
        </tr>
    
        <tr>
            <th>01:00 - 02:00</td>
            
                <td>Cumm. Skill</td>
                <td>Sports</td>
                <td>English</td>
                <td>Computer Lab</td>
                <td>Header</td>
                <td>Header</td>
    
            </div>
        </tr>
    
        <tr>
            <th>02:00 - 03:00</td>
            
                <td>Header</td>
                <td>Header</td>
                <td>Header</td>
                <td>Header</td>
                <td>Header</td>
                <td>Header</td>
            </div>
        </tr>
    </table>
</body>

2 个答案:

答案 0 :(得分:3)

您的代码无效,请尝试此操作。

 table tr:first-of-type 

不要在div中插入表格元素,要么使用特定的选择器,要么将类/ id赋予td / tr。

正如您所知,内联CSS是一种不好的做法,因此请将其移到单独的CSS文件中。

  body {
      font-family: arial;
  }
  th, td {
      margin: 0;
      text-align: center;
      border-collapse: collapse;
      outline: 1px solid #e3e3e3;
  }
  td {
      padding: 5px 10px;
  }
  th {
      background: #666;
      color: white;
      padding: 5px 10px;
  }
  td:hover {
      cursor: pointer;
      background: #666;
      color: white;
  }
  table tr:first-of-type {
      font-size:30px;
  }
<title>Timetable</title>
<table width="80%" align="center">
    <tr>
        <th>Time</th>
        <th>Monday</th>
        <th>Tuesday</th>
        <th>Wednesday</th>
        <th>Thrusday</th>
        <th>Friday</th>
        <th>Saturday</th>
    </tr>
    <tr>
        <th>10:00 - 11:00</th>
        <td>Physics-1</td>
        <td>English</td>
        <td title="No Class" class="Holiday"></td>
        <td>Chemestry-1</td>
        <td>Alzebra</td>
        <td>Physical</td>
        </div>
    </tr>
    <tr>
        <th>11:00 - 12:00</td>
            <td>Math-2</td>
            <td>Chemestry-2</td>
            <td>Physics-1</td>
            <td>Hindi</td>
            <td>English</td>
            <td>Soft Skill</td>
            </div>
    </tr>
    <tr>
        <th>12:00 - 01:00</td>
            <td>Hindi</td>
            <td>English</td>
            <td>Math-1</td>
            <td>Chemistry</td>
            <td>Physics</td>
            <td>Chem.Lab</td>
            </div>
    </tr>
    <tr>
        <th>01:00 - 02:00</td>
            <td>Cumm. Skill</td>
            <td>Sports</td>
            <td>English</td>
            <td>Computer Lab</td>
            <td>Header</td>
            <td>Header</td>
            </div>
    </tr>
    <tr>
        <th>02:00 - 03:00</td>
            <td>Header</td>
            <td>Header</td>
            <td>Header</td>
            <td>Header</td>
            <td>Header</td>
            <td>Header</td>
            </div>
    </tr>
</table>

答案 1 :(得分:0)

由于您所做的代码无效。检查一下它可能对你有帮助......

&#13;
&#13;
 body {
   font-family: arial;
 }
 th,
 td {
   margin: 0;
   text-align: center;
   border-collapse: collapse;
   outline: 1px solid #e3e3e3;
 }
 td {
   padding: 5px 10px;
 }
 th {
   background: #666;
   color: white;
   padding: 5px 10px;
 }
 td:hover {
   cursor: pointer;
   background: #666;
   color: white;
 }
&#13;
<table width="80%" align="center">
  <tr>
    <th>Time</th>
    <th>Monday</th>
    <th>Tuesday</th>
    <th>Wednesday</th>
    <th>Thrusday</th>
    <th>Friday</th>
    <th>Saturday</th>
  </tr>

  <tr>
    <th>10:00 - 11:00</th>

    <td>Physics-1</td>
    <td>English</td>
    <td title="No Class" class="Holiday"></td>
    <td>Chemestry-1</td>
    <td>Alzebra</td>
    <td>Physical</td>
  </tr>

  <tr>
    <th>11:00 - 12:00</td>

      <td>Math-2</td>
      <td>Chemestry-2</td>
      <td>Physics-1</td>
      <td>Hindi</td>
      <td>English</td>
      <td>Soft Skill</td>
  </tr>

  <tr>
    <th>12:00 - 01:00</td>

      <td>Hindi</td>
      <td>English</td>
      <td>Math-1</td>
      <td>Chemistry</td>
      <td>Physics</td>
      <td>Chem.Lab</td>
  </tr>

  <tr>
    <th>01:00 - 02:00</td>

      <td>Cumm. Skill</td>
      <td>Sports</td>
      <td>English</td>
      <td>Computer Lab</td>
      <td>Header</td>
      <td>Header</td>

  </tr>

  <tr>
    <th>02:00 - 03:00</td>

      <td>Header</td>
      <td>Header</td>
      <td>Header</td>
      <td>Header</td>
      <td>Header</td>
      <td>Header</td>
  </tr>
</table>
&#13;
&#13;
&#13;