为什么这个 table 在 Chrome 和 Firefox 之间呈现不同?
Why does this table render differently between Chrome and Firefox?
我有一个 table 似乎在 Chrome 和 Firefox 之间呈现不同。 Chrome 输出正确,而 Firefox 输出不正确。
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>
在 Firefox(和 Edge)上,table 中的第三项总是放在自己的行上,无论水平 space 有多少。
将 display: inline;
应用到 table 行(通过 class .person
)实际上没有任何意义 - 要么使用 DIV 并根据 [=35 应用=] 或者您使用 "real" table(即 HTML table 元素,例如 table
、trand
td`,因为它会没有 CSS 规则)。
其他所有内容,即每个 "mixture" 默认 table 布局属性和不同的 CSS display
定义仅取决于浏览器的 tolerance/interpretation体验。但我怀疑这个(即 tr
标签及其 display: inline
定义)是 "native" HTML 布局属性和 CSS.[=19 的有效组合=]
例如,我会在 DIV 上使用 flexbox 属性,而不是所有那些非真实的 table 元素,如下所示:
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>
我有一个 table 似乎在 Chrome 和 Firefox 之间呈现不同。 Chrome 输出正确,而 Firefox 输出不正确。
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>
在 Firefox(和 Edge)上,table 中的第三项总是放在自己的行上,无论水平 space 有多少。
将 display: inline;
应用到 table 行(通过 class .person
)实际上没有任何意义 - 要么使用 DIV 并根据 [=35 应用=] 或者您使用 "real" table(即 HTML table 元素,例如 table
、trand
td`,因为它会没有 CSS 规则)。
其他所有内容,即每个 "mixture" 默认 table 布局属性和不同的 CSS display
定义仅取决于浏览器的 tolerance/interpretation体验。但我怀疑这个(即 tr
标签及其 display: inline
定义)是 "native" HTML 布局属性和 CSS.[=19 的有效组合=]
例如,我会在 DIV 上使用 flexbox 属性,而不是所有那些非真实的 table 元素,如下所示:
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>