0

我希望它有一个半红半蓝的表格,在边框和文本之间有一些填充。我只是无法弄清楚为什么填充属性不适用于此

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title> Practice Exercise </title
<style>
.red{background-color:red}
.blue{background-color:blue}
table{border-collapse:collapse;padding:40px;}
</style>
</head>
<body>
<table border ="1">
<tr>
<th class="red"> State </th>
<th class="blue"> Capital </th>
</tr>
<td class="red"> Utah </td>
<td class="blue"> Salt Lake City </td>
</tr>
<td class="red"> Texas </td>
<td class="blue"> Austin </td>
</tr>
<td class="red"> Tennesse </td>
<td class="blue> Nashville </td
</tr>
</table>
</body>
</html>
4

1 回答 1

1

你的标记中有很多错别字:我会把它们都指出来。

<table border="1">
    <tr>
        <th class="red">State</th>
        <th class="blue">Capital</th>
    </tr>
    <tr> <!-- missing -->
        <td class="red">Utah</td>
        <td class="blue">Salt Lake City</td>
    </tr>
    <tr> <!-- missing -->
        <td class="red">Texas</td>
        <td class="blue">Austin</td>
    </tr>
    <tr>  <!-- missing -->
    <td class="red">Tennesse</td>
    <td class="blue">Nashville</td>  <!-- missing one " after blue, and one > after </td -->
    </tr>
</table>

另外:你在 上应用了填充table,你应该把它应用在td, th这样的:

CSS

td, th
{
    padding: 5px;
}

工作小提琴

于 2013-09-12T22:02:27.200 回答