![](/img/trans.png)
[英]Table with fixed position of columns without setting height and width of td and th
[英]TH and TD height not setting
在我正在创建的表格中,我无法让th
和td
达到我赋予的高度。 如您在我的代码中所看到的,看起来这两个字段和th
正在填充整个表格高度。
无论如何,有没有将td
和th
设置为我给的80px
和60px
?
#staff-table { width: 100%; height: 600px; border: 1px solid #CDCDCD; } th, td { color: 303030; padding: 10px; } th { font-family: 'Source Sans Pro', sans-serif; font-size: 1.2em; font-weight: 600; height: 80px; background: #F7F7F7; } th:hover { background: #F7F7F7; } tr { border-bottom: 1px solid #EBEBEB; transition:.5s; -webkit-transition:.5s; } tr:hover { background: #09afdf;/*rgba(9, 175, 223, .4);*/ transition:.5s; -webkit-transition:.5s; } td { font-size: 1em; font-family: 'Lato', sans-serif; height: 60px; }
<table id="staff-table"> <tr> <th>First Name</th> <th>Last Name</th> <th>Print Name</th> <th>Type</th> <th>Balance</th> </tr> <tr> <td>Georg</td> <td>Reese</td> <td>George Reese</td> <td>Primary</td> <td>32</td> </tr> <tr> <td>Bob</td> <td>Synder</td> <td>Bob Snyder</td> <td>Sales</td> <td>10</td> </tr> </table>
是的,通过删除height: 600px
#staff-table
规则上的height: 600px
#staff-table { width: 100%; min-height: 100px; /* added based on comment, to keep a minimum height */ border: 1px solid #CDCDCD; } th, td { color: #303030; padding: 10px; } th { font-family: 'Source Sans Pro', sans-serif; font-size: 1.2em; font-weight: 600; height: 80px; background: #F7F7F7; } th:hover { background: #F7F7F7; } tr { border-bottom: 1px solid #EBEBEB; transition:.5s; -webkit-transition:.5s; } tr:hover { background: #09afdf;/*rgba(9, 175, 223, .4);*/ transition:.5s; -webkit-transition:.5s; } td { font-size: 1em; font-family: 'Lato', sans-serif; height: 60px; }
<table id="staff-table"> <tr> <th>First Name</th> <th>Last Name</th> <th>Print Name</th> <th>Type</th> <th>Balance</th> </tr> <tr> <td>Georg</td> <td>Reese</td> <td>George Reese</td> <td>Primary</td> <td>32</td> </tr> <tr> <td>Bob</td> <td>Synder</td> <td>Bob Snyder</td> <td>Sales</td> <td>10</td> </tr> </table>
如果您打算让最上面的一行为600px
那么您需要将其他行设置为自己的特定ID或类。 #staff-table
会首先应用到所有这些对象,因此它具有该height
。
#staff-table { width: 100%; border: 1px solid #CDCDCD; } th, td { color: 303030; padding: 10px; } th { font-family: 'Source Sans Pro', sans-serif; font-size: 1.2em; font-weight: 600; height: 80px; background: #F7F7F7; } th:hover { background: #F7F7F7; } tr { border-bottom: 1px solid #EBEBEB; transition:.5s; -webkit-transition:.5s; } tr:hover { background: #09afdf;/*rgba(9, 175, 223, .4);*/ transition:.5s; -webkit-transition:.5s; } td { font-size: 1em; font-family: 'Lato', sans-serif; height: 60px; }
<table id="staff-table"> <tr> <th>First Name</th> <th>Last Name</th> <th>Print Name</th> <th>Type</th> <th>Balance</th> </tr> <tr> <td>Georg</td> <td>Reese</td> <td>George Reese</td> <td>Primary</td> <td>32</td> </tr> <tr> <td>Bob</td> <td>Synder</td> <td>Bob Snyder</td> <td>Sales</td> <td>10</td> </tr> </table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.