Julian Lachniet
Julian Lachniet

Reputation: 323

Why does this table render differently between Chrome and Firefox?

I have a table that seems to be rendering differently between Chrome and Firefox. The Chrome output is correct, and the Firefox output isn't.

body {
  background-color: #e1e1e1;
  word-wrap: break-word
}

#about-table {
  margin: 0 auto;
}

.panel {
  background-color: #f5f5f6;
  border-radius: 4px;
  box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.75);
  color: #1c1c1c;
  margin: 16px;
  padding: 32px;
  text-align: center;
}

.person {
  display: inline;
}

.portrait {
  width: 100%;
}

.portrait-container {
  max-width: 256px;
  width: 50%;
}

.portrait-label {
  font-weight: 600;
  width: 128px;
}
<head>
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css" />
  <link rel="stylesheet" href="/lib/index2.css" />
</head>
<body>
  <div class="panel">
    <table id="about-table">
      <tr class="person">
        <td class="portrait-container"><img class="portrait" src="/img/head-julian.jpg" /></td>
        <td class="portrait-label">Person 1</td>
      </tr>
      <tr class="person">
        <td class="portrait-container"><img class="portrait" src="/img/head-simon.jpg" /></td>
        <td class="portrait-label">Person 2</td>
      </tr>
      <tr class="person">
        <td class="portrait-container"><img class="portrait" src="/img/head-jacob.jpg" /></td>
        <td class="portrait-label">Person 3</td>
        </tr>
    </table>
  </div>
</body>

On Firefox (and Edge), the third item in the table always gets put on its own line, regardless of how much horizontal space there is.

Upvotes: 1

Views: 952

Answers (1)

Johannes
Johannes

Reputation: 67758

To apply display: inline; to a table row (via class .person) doesn't really make sense - either you use DIVs and apply according CSS to them or you use a "real" table (i.e. HTML table elements like table, trandtd`, as it would be without that CSS rule).

Everything else, i.e. every "mixture" of default table layout properties and different CSS display definitions just depends on the browser's tolerance/interpretation which you are experiencing. But I doubt that this (i.e. the tr tags and their display: inline definition) is a valid combination of "native" HTML layout properties and CSS.

I would for example use flexbox properties on DIVs instead of all those not-real-table-elements as shown below:

body {
  background-color: #e1e1e1;
  word-wrap: break-word
}

#about-table {
    display: flex;
    justify-content: center;

}

.panel {
  background-color: #f5f5f6;
  border-radius: 4px;
  box-shadow: 0px 0px 10px 0px rgba(0,0,0,0.75);
  color: #1c1c1c;
  margin: 16px;
  padding: 32px;
  text-align: center;
}

.person {
  display: flex;
  width: 30%;
  align-items: center;
}

.portrait {
  width: 100%;
}

.portrait-container {
  max-width: 256px;
  width: 50%;
}

.portrait-label {
  font-weight: 600;
  width: 128px;
}
<head>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.0/normalize.min.css" />
    <link rel="stylesheet" href="/lib/index2.css" />
</head>
<body>
  <div class="panel">
    <div id="about-table">
      <div class="person">
        <div class="portrait-container"><img class="portrait" src="/img/head-julian.jpg" /></div>
        <div class="portrait-label">Person 1</div>
      </div>
      <div class="person">
        <div class="portrait-container"><img class="portrait" src="/img/head-simon.jpg" /></div>
        <div class="portrait-label">Person 2</div>
      </div>
      <div class="person">
        <div class="portrait-container"><img class="portrait" src="/img/head-jacob.jpg" /></div>
        <div class="portrait-label">Person 3</div>
        </div>
    </div>
  </div>
</body>

Upvotes: 2

Related Questions