Why are the <tr> tags in my HTML code not displayed in order on my browser?

Viewed 43

So I'm making a website as a test. The code can be seen below.

* {
    background: #000000;
    color: #dddddd;
    margin: 0;
    padding: 0;
}

body {
    font-family: Consolas;
}

button.header {
    border-width: 0;
}

table { width: 100%; }
<!DOCTYPE html>
<html lang="en">

    <head>
        <title>test title</title>
        <link rel="stylesheet" href="start.css">
    </head>

    <body>
        <table style="padding-top: 0.8rem;">
            <tr> <!-- Title, Buttons -->
                <th style="text-align: left; padding-left: 0.8rem;">
                    <h1>test site title</h1>
                </th>
                <th style="text-align: right; padding-right: 0.8rem;">
                   <button class="header"> ABOUT </button>
                   <button class="header"> PROJECTS </button>
                   <button class="header"> CONTACT </button>
                </th>
            </tr>
            <tr>
                Test
            </tr>
        </table>
    </body>
</html>

The output is seen below: browser output

The error here is that the second <tr> tag with the text "Test" is displayed before the first, which contains the buttons and title.

Why is that happening? How can I affect the order of my table rows?

2 Answers

You need to wrap "test" inside a Data Cell (<td>) element.

* {
  background: #000000;
  color: #dddddd;
  margin: 0;
  padding: 0;
}

body {
  font-family: Consolas;
}

button.header {
  border-width: 0;
}

table {
  width: 100%;
}
<table style="padding-top: 0.8rem;">
  <tr>
    <th style="text-align: left; padding-left: 0.8rem;">
      <h1>test site title</h1>
    </th>
    <th style="text-align: right; padding-right: 0.8rem;">
      <button class="header"> ABOUT </button>
      <button class="header"> PROJECTS </button>
      <button class="header"> CONTACT </button>
    </th>
  </tr>
  <tr><td>Test</td></tr>
</table>

Related