我无法为 HTML table 设置边框

I can't set border for an HTML table

我正在学习 HTML 和一点点 CSS。我在为 HTML 边框设置 table 边框时遇到问题。 我输入 CSS 代码,宽度和高度代码以及文本对齐代码也可以正常工作,但边框代码不起作用。 这是我的代码:

<table>
  <style>
    table,
    th,
    td {
      text-align: left;
      border: 10px red;
      border-collapse: collapse;
      width: 800px;
      height: 100px;
    }
  </style>
  <tr>
    <th>Player LastName</th>
    <th>Player Jersey Number</th>
    <th>nationallity</th>
    <tr>
      <td>Reus</td>
      <td>11</td>
      <td>Germany</td>
      <tr>
        <td>Haaland</td>
        <td>9</td>
        <td>norway</td>
        <tr>
          <td>Kobel</td>
          <td>1</td>
          <td>Switzerland</td>
</table>

这是我网站上的结果:result in my webpage

您需要定义边框类型。例如 soliddotted。有关边界的详细信息,请参阅 here 属性

<table>
  <style>
    table,
    th,
    td {
      text-align: left;
      border: 10px solid red;
      width: 800px;
      height: 100px;
    }
  </style>
  <tr>
    <th>Player LastName</th>
    <th>Player Jersey Number</th>
    <th>nationallity</th>
    <tr>
      <td>Reus</td>
      <td>11</td>
      <td>Germany</td>
      <tr>
        <td>Haaland</td>
        <td>9</td>
        <td>norway</td>
        <tr>
          <td>Kobel</td>
          <td>1</td>
          <td>Switzerland</td>
</table>

您没有提到边框类型:

这是更新后的 css 代码,请使用以下 css 代码

  table,th,td {
            text-align: left;
            border: 10px red solid;
            width: 800px;
            height: 100px;
        }

您必须将边框 样式 添加到您的边框定义中(实线、点线或其他):border: 10px solid red;

(并且您应该关闭您的 <tr> 标签!)

table,
th,
td {
  text-align: left;
  border: 10px solid red;
  border-collapse: collapse;
  width: 800px;
  height: 100px;
}
<table>
  <tr>
    <th>Player LastName</th>
    <th>Player Jersey Number</th>
    <th>nationallity</th>
  </tr>
  <tr>
    <td>Reus</td>
    <td>11</td>
    <td>Germany</td </tr>
  </tr>

  <tr>
    <td>Haaland</td>
    <td>9</td>
    <td>norway</td>
  </tr>

  <tr>
    <td>Kobel</td>
    <td>1</td>
    <td>Switzerland</td>
  </tr>
</table>

祝你在 HTML 和 CSS 的学习道路上好运。

当您使用“Border Shorthand”时始终遵循语法,您的代码缺少边框类型。此处参考:https://www.w3schools.com/css/css_border_shorthand.asp

使用此 CSS 代码:

table,
th,
td {
  text-align: left;
  border: 10px solid red;
  width: 800px;
  height: 100px;
}