【问题标题】:Firefox table cell width completly different than Chrome'sFirefox 表格单元格宽度与 Chrome 完全不同
【发布时间】:2020-12-04 09:42:00
【问题描述】:

我的表格单元格宽度有问题。在 Chrome 上它可以完美运行,但在 Firefox 上它看起来有很大不同,我不知道是什么原因造成的。

这是镀铬的,看起来很完美:

这是 Firefox 的,被挤得紧紧的:

知道这是为什么吗?这是我的代码。

/* Latest games */
.lp-latestgames {
    height: 466px;
}
.lp-latestgames .title {
    margin-left: 460px;
    margin-top: 56px;
    margin-bottom: 21px;
}
.lp-latestgames .table {
    margin-bottom: 0;
}
.lp-latestgames .table thead {
    background-color: rgba(0, 0, 0, 0.45);
}
.lp-latestgames .table thead th {
    font-size: 16px;
    font-weight: 500 !important;
    color: white;
    height: 49px;
    vertical-align: middle;
}
.lp-latestgames .table thead > tr > th { border-bottom: none; }
.lp-latestgames .table tbody > tr > td {
    height: 81px;
    border-top: 2px solid #111316;
    background-color: rgba(0, 0, 0, 0.19);
    vertical-align: middle;
    font-size: 14px;
    font-weight: 500;
    color: white;
}
.lp-latestgames .table tbody > tr:first-child > td { border-top: none; }
.lp-latestgames .table tbody > tr > td:first-child,
.lp-latestgames .table thead > tr > th:first-child{
    /* ÜBERARBEITEN!!!!! */
    padding-left: 460px;
    max-width: 200px;
}
.lp-latestgames .table tbody > tr > td:last-child,
.lp-latestgames .table thead > tr > th:last-child{
    /* ÜBERARBEITEN!!!!! */
    padding-right: 460px;
    max-width: 200px;
}
.lp-latestgames .table tbody > tr > td > .gd-c-versus {
    display: block;
    font-weight: normal;
    font-family: Arial;
    color: #494949;
}
.lp-latestgames .table thead > tr > th:nth-child(4),
.lp-latestgames .table thead > tr > th:nth-child(5),
.lp-latestgames .table tbody > tr > td:nth-child(4),
.lp-latestgames .table tbody > tr > td:nth-child(5) {
    text-align: center;
}
<div class="lp-latestgames">
        <!-- Games -->
        <table class="table">
            <thead>
            <tr>
                <th>Name <img src="img/gd_content_arrow_dn.png"></th>
                <th>Price Pool <img src="img/gd_content_arrow_dn.png"></th>
                <th>Entry <img src="img/gd_content_arrow_dn.png"></th>
                <th>Avg Skill <img src="img/gd_content_arrow_dn.png"></th>
                <th>Time Remaining <img src="img/gd_content_arrow_up.png"></th>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>Im bored. Fite me<span class="gd-c-versus">1 vs 1</span></td>
                <td><img src="img/gd_content_coin.png"> 20</td>
                <td><img src="img/gd_content_coin.png"> 10</td>
                <td><input type="text" value="730" class="circle"></td>
                <td>00:00:32</td>
            </tr>
            <tr>
                <td>EG vs LGD - Wild Cards Entry<span class="gd-c-versus">5 vs 5</span></td>
                <td><img src="img/gd_content_coin.png"> 1.500.000</td>
                <td><img src="img/gd_content_coin.png"> 20</td>
                <td><input type="text" value="980" class="circle"></td>
                <td>00:01:47</td>
            </tr>
            <tr>
                <td>cyka blyat<span class="gd-c-versus">5 vs 5</span></td>
                <td><img src="img/gd_content_coin.png"> 20</td>
                <td><img src="img/gd_content_coin.png"> 10</td>
                <td><input type="text" value="730" class="circle"></td>
                <td>00:02:4</td>
            </tr>
            </tbody>
        </table>
    </div>

【问题讨论】:

  • 看我的回答,几个月前我遇到了同样的问题。

标签: html css google-chrome firefox css-tables


【解决方案1】:

您是否在 html 页面中声明了&lt;!DOCTYPE&gt;,如果没有,请尝试一下。这个 doctype 是向网络浏览器指示页面是用什么版本的 HTML 编写的。

【讨论】:

  • 好吧,我的第一行有&lt;!DOCTYPE html&gt;
【解决方案2】:

尝试添加这个:

.table { table-layout: fixed }

见sn-p 见POST

/* Latest games */

.lp-latestgames {
  height: 466px;
}
.lp-latestgames .title {
  margin-left: 460px;
  margin-top: 56px;
  margin-bottom: 21px;
}
.lp-latestgames .table {
  margin-bottom: 0;
  table-layout: fixed;    /*<<<=====  ADD THIS RULE RIGHT HERE */ 
}
.lp-latestgames .table thead {
  background-color: rgba(0, 0, 0, 0.45);
}
.lp-latestgames .table thead th {
  font-size: 16px;
  font-weight: 500 !important;
  color: white;
  height: 49px;
  vertical-align: middle;
}
.lp-latestgames .table thead > tr > th {
  border-bottom: none;
}
.lp-latestgames .table tbody > tr > td {
  height: 81px;
  border-top: 2px solid #111316;
  background-color: rgba(0, 0, 0, 0.19);
  vertical-align: middle;
  font-size: 14px;
  font-weight: 500;
  color: white;
}
.lp-latestgames .table tbody > tr:first-child > td {
  border-top: none;
}
.lp-latestgames .table tbody > tr > td:first-child,
.lp-latestgames .table thead > tr > th:first-child {
  /* ÜBERARBEITEN!!!!! */
  padding-left: 460px;
  max-width: 200px;
}
.lp-latestgames .table tbody > tr > td:last-child,
.lp-latestgames .table thead > tr > th:last-child {
  /* ÜBERARBEITEN!!!!! */
  padding-right: 460px;
  max-width: 200px;
}
.lp-latestgames .table tbody > tr > td > .gd-c-versus {
  display: block;
  font-weight: normal;
  font-family: Arial;
  color: #494949;
}
.lp-latestgames .table thead > tr > th:nth-child(4),
.lp-latestgames .table thead > tr > th:nth-child(5),
.lp-latestgames .table tbody > tr > td:nth-child(4),
.lp-latestgames .table tbody > tr > td:nth-child(5) {
  text-align: center;
}
<div class="lp-latestgames">
  <!-- Games -->
  <table class="table">
    <thead>
      <tr>
        <th>Name
          <img src="img/gd_content_arrow_dn.png">
        </th>
        <th>Price Pool
          <img src="img/gd_content_arrow_dn.png">
        </th>
        <th>Entry
          <img src="img/gd_content_arrow_dn.png">
        </th>
        <th>Avg Skill
          <img src="img/gd_content_arrow_dn.png">
        </th>
        <th>Time Remaining
          <img src="img/gd_content_arrow_up.png">
        </th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>Im bored. Fite me<span class="gd-c-versus">1 vs 1</span>
        </td>
        <td>
          <img src="img/gd_content_coin.png">20</td>
        <td>
          <img src="img/gd_content_coin.png">10</td>
        <td>
          <input type="text" value="730" class="circle">
        </td>
        <td>00:00:32</td>
      </tr>
      <tr>
        <td>EG vs LGD - Wild Cards Entry<span class="gd-c-versus">5 vs 5</span>
        </td>
        <td>
          <img src="img/gd_content_coin.png">1.500.000</td>
        <td>
          <img src="img/gd_content_coin.png">20</td>
        <td>
          <input type="text" value="980" class="circle">
        </td>
        <td>00:01:47</td>
      </tr>
      <tr>
        <td>cyka blyat<span class="gd-c-versus">5 vs 5</span>
        </td>
        <td>
          <img src="img/gd_content_coin.png">20</td>
        <td>
          <img src="img/gd_content_coin.png">10</td>
        <td>
          <input type="text" value="730" class="circle">
        </td>
        <td>00:02:4</td>
      </tr>
    </tbody>
  </table>
</div>

【讨论】:

  • 没用,现在看起来像这样:link 在 chrome 和 FF 上
  • 这不是目的吗?让 Chrome 的行为像 Firefox 一样,反之亦然?如果您可以在两种浏览器上获得相同的外观,那么算您的祝福。即使外观不理想,您也可以继续在 Chrome 上工作,并确信 Firefox 不会再次出现问题。
【解决方案3】:

尝试使用 rem 而不是 px 来设置 th 或 td 宽度 每个rem等于16px

【讨论】: