英文:
HTML table does not line up as expected
问题
我已经创建了一个基于直播聊天活动的PHP应用程序,它呈现一个网页。它的排版有问题。
问题在于“标题”(在这个示例中显示为“这是直播标题应该在的地方”)应该占用所有的作者和Mod区域,并延伸到“消息”区域的开头(为此使用了colspan=2),但实际上它停在了Mod列。我正在使用colspan来控制这个,但colspan似乎没有按我期望的那样工作。我尝试过在多个平台上使用Chrome以及在iOS上使用最新的Safari,结果都一样。
换句话说,为了确保清楚,我看到的问题在于红色的那一行。我期望标题会延伸到消息区域,紧挨着它的是URL,而不是停在Mod列。另外,如果仔细看,Mod列的标题与其下面的值并不完全对齐,这可能是相同问题的结果。
通常我可以相当可靠地做到5以内的算术,但在这种情况下,我和计算机对于2加3的结果存在分歧。你知道我必须做什么才能解决这个问题吗?
英文:
I have created a PHP application that presents a web page based on livestream chat activity. It's not lining up properly.
The problem is that the "title" (which in this example says "This is where the livestream title should be") should consume all of the Author and Mod areas, and reach into the beginning of the "messages" area (which was created with colspan=2 for that purpose), but instead it stops at the Mod column. I'm using colspan to control this, and colspan does not seem to be doing what I expect. I have tried this with Chrome on several platforms, and with latest Safari on iOS... all with the same result.
Put another way, to be sure it's clear, the issue I see, is on the red-colored line. I expect the title to dip into the Messages area, with the URL immediately next to it, and not to stop at the Mod column. Also, if one looks closely, that Mod column heading doesn't exactly align on the right side with the values below it, and that's probably a result of the same problem.
I can usually do arithmetic pretty reliably up to 5, but in this instance the computer and I disagree about what 2+3 adds up to. Any idea what I must do in order to resolve this?
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
headingLink {
color: white;
text-decoration: none;
}
.freeze-table {
border-spacing: 0;
padding: 0;
}
thead th {
top: 0;
position: sticky;
background-color: #666;
color: #fff;
z-index: 20;
min-height: 30px;
height: 30px;
text-align: left;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
th,
td {
padding: 0 5px;
font-name: Courier;
font-size: 12;
outline: 1px solid #ccc;
border: none;
outline-offset: -1px;
padding-left: 5px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
tr {
min-height: 25px;
height: 25px;
}
pageElement {
display: flex;
flex-wrap: nowrap;
align-items: center
}
* {
padding: 0;
margin: 0;
}
.fit {
/* set relative picture size */
max-width: 100%;
max-height: 100%;
}
.center {
display: block;
margin: auto;
}
.imgbox {
display: grid;
width: 100%;
}
.center-fit {
max-width: 100%;
max-height: 100vh;
margin: auto;
}
<!-- language: lang-html -->
<table>
<thead>
<tr>
<th colspan=2 style='text-align:center;font-weight:bold;'>&nbsp;Date/Time&nbsp;</th>
<th style='font-weight:bold;'>Author</th>
<th style='font-weight:bold;text-align:center;'>Mod</th>
<th colspan=2 style='font-weight:bold;'>Message</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan=2 style='text-align:center;color:red;font-weight:bold;'>2023-05-14</td>
<td colspan=3 style='color:red;font-weight:bold;'>2023-05-14 This is where the livesteam title should be</td>
<td style='text-align:right;'><a href='https://youtu.be/dummy'>https://youtu.be/dummy</a></td>
</tr>
<tr>
<td style='text-align:right;color:Black;'>1&nbsp;R</td>
<td style='text-align:center;color:Black;'>07:21&nbsp;(1:14:21)</td>
<td style='text-align:left;color:Black;'>Some Watcher</td>
<td style='text-align:center;color:Black;'> (Mod)</td>
<td colspan=2 style='text-align:left;color:Black;'><a href="https://youtu.be/ddummy?t=4461" target="_blank">_</a>&nbsp;Thanks for the concert Brother</td>
</tr>
</tbody>
</table>
<!-- end snippet -->
答案1
得分: 1
以下是您提供的代码的中文翻译部分:
headingLink {
color: white;
text-decoration: none;
}
.freeze-table {
border-spacing: 0;
padding: 0;
}
thead th {
top: 0;
position: sticky;
background-color: #666;
color: #fff;
z-index: 20;
min-height: 30px;
height: 30px;
text-align: left;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
th,
td {
padding: 0 5px;
font-name: Courier;
font-size: 12;
outline: 1px solid #ccc;
border: none;
outline-offset: -1px;
padding-left: 5px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
tr {
min-height: 25px;
height: 25px;
}
pageElement {
display: flex;
flex-wrap: nowrap;
align-items: center;
}
* {
padding: 0;
margin: 0;
}
.fit {
/* 设置相对图片尺寸 */
max-width: 100%;
max-height: 100%;
}
.center {
display: block;
margin: auto;
}
.imgbox {
display: grid;
width: 100%;
}
.center-fit {
max-width: 100%;
max-height: 100vh;
margin: auto;
}
<table>
<thead>
<tr>
<th colspan=2 style='text-align:center;font-weight:bold;'> 日期/时间 </th>
<th style='font-weight:bold;'>作者</th>
<th style='font-weight:bold;text-align:center;'>修改</th>
<th colspan=2 style='font-weight:bold;'>消息</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan=2 style='text-align:center;color:red;font-weight:bold;'>2023-05-14</td>
<td colspan=3>
<table>
<tr>
<td style='color:red;font-weight:bold;'>2023-05-14 这是直播标题应该放置的地方</td>
<td style='text-align:right;'><a href='https://youtu.be/dummy'>https://youtu.be/dummy</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td style='text-align:right;color:Black;'>1 R</td>
<td style='text-align:center;color:Black;'>07:21 (1:14:21)</td>
<td style='text-align:left;color:Black;'>某位观众</td>
<td style='text-align:center;color:Black;'> (修改)</td>
<td colspan=2 style='text-align:left;color:Black;'><a href="https://youtu.be/ddummy?t=4461" target="_blank">_</a> 感谢演唱会兄弟</td>
</tr>
</tbody>
</table>
这是您提供的代码的中文翻译部分。如有其他需要,请告诉我。
英文:
Try this:
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
headingLink {
color: white;
text-decoration: none;
}
.freeze-table {
border-spacing: 0;
padding: 0;
}
thead th {
top: 0;
position: sticky;
background-color: #666;
color: #fff;
z-index: 20;
min-height: 30px;
height: 30px;
text-align: left;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
th,
td {
padding: 0 5px;
font-name: Courier;
font-size: 12;
outline: 1px solid #ccc;
border: none;
outline-offset: -1px;
padding-left: 5px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
tr {
min-height: 25px;
height: 25px;
}
pageElement {
display: flex;
flex-wrap: nowrap;
align-items: center
}
* {
padding: 0;
margin: 0;
}
.fit {
/* set relative picture size */
max-width: 100%;
max-height: 100%;
}
.center {
display: block;
margin: auto;
}
.imgbox {
display: grid;
width: 100%;
}
.center-fit {
max-width: 100%;
max-height: 100vh;
margin: auto;
}
<!-- language: lang-html -->
<table>
<thead>
<tr>
<th colspan=2 style='text-align:center;font-weight:bold;'>&nbsp;Date/Time&nbsp;</th>
<th style='font-weight:bold;'>Author</th>
<th style='font-weight:bold;text-align:center;'>Mod</th>
<th colspan=2 style='font-weight:bold;'>Message</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan=2 style='text-align:center;color:red;font-weight:bold;'>2023-05-14</td>
<td colspan=3>
<table>
<tr>
<td style='color:red;font-weight:bold;'>2023-05-14 This is where the livesteam title should be</td>
<td style='text-align:right;'><a href='https://youtu.be/dummy'>https://youtu.be/dummy</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td style='text-align:right;color:Black;'>1&nbsp;R</td>
<td style='text-align:center;color:Black;'>07:21&nbsp;(1:14:21)</td>
<td style='text-align:left;color:Black;'>Some Watcher</td>
<td style='text-align:center;color:Black;'> (Mod)</td>
<td colspan=2 style='text-align:left;color:Black;'><a href="https://youtu.be/ddummy?t=4461" target="_blank">_</a>&nbsp;Thanks for the concert Brother</td>
</tr>
</tbody>
</table>
<!-- end snippet -->
Have added new <table>
with two <td>
(title and link) inside of <td colspan=3>
答案2
得分: 1
Table cell calculation is complex and fraught. To resolve your problem you need at least one row with individual column cells to act as a basis for the layout. You can then hide them with CSS and ARIA attributes (the latter for accessibility).
.dummy-row {
height: 1px;
visibility: hidden;
}
.freeze-table {
border-spacing: 0;
padding: 0;
}
thead th {
top: 0;
position: sticky;
background-color: #666;
color: #fff;
z-index: 20;
min-height: 30px;
height: 30px;
text-align: left;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
th,
td {
padding: 0 5px;
font-name: Courier;
font-size: 12;
outline: 1px solid #ccc;
border: none;
outline-offset: -1px;
padding-left: 5px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
tr {
min-height: 25px;
height: 25px;
}
* {
padding: 0;
margin: 0;
}
.fit {
/* set relative picture size */
max-width: 100%;
max-height: 100%;
}
.center {
display: block;
margin: auto;
}
.imgbox {
display: grid;
width: 100%;
}
.center-fit {
max-width: 100%;
max-height: 100vh;
margin: auto;
}
<table>
<thead>
<tr>
<th colspan=2 style='text-align:center;font-weight:bold;'> Date/Time </th>
<th style='font-weight:bold;'>Author</th>
<th style='font-weight:bold;text-align:center;'>Mod</th>
<th colspan=2 style='font-weight:bold;'>Message</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan=2 style='text-align:center;color:red;font-weight:bold;'>2023-05-14</td>
<td colspan=3 style='color:red;font-weight:bold;'>2023-05-14 This is where the livestream title should be</td>
<td style='text-align:right;'><a href='https://youtu.be/dummy'>https://youtu.be/dummy</a></td>
</tr>
<tr>
<td style='text-align:right;color:Black;'>1 R</td>
<td style='text-align:center;color:Black;'>07:21 (1:14:21)</td>
<td style='text-align:left;color:Black;'>Some Watcher</td>
<td style='text-align:center;color:Black;'> (Mod)</td>
<td colspan=2 style='text-align:left;color:Black;'><a href="https://youtu.be/ddummy?t=4461" target="_blank">_</a> Thanks for the concert Brother</td>
</tr>
<tr class="dummy-row" aria-hidden="true">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
Please note that the code and text have been translated, and any code-related content remains in its original form.
英文:
Table cell calculation is complex and fraught. To resolve your problem you need at least one row with individual column cells to act as a basis for the layout.
You can then hide them with CSS and ARIA attributes (the latter for accessibility).
<!-- begin snippet: js hide: false console: true babel: false -->
<!-- language: lang-css -->
.dummy-row {
height: 1px;
visibility: hidden;
}
.freeze-table {
border-spacing: 0;
padding: 0;
}
thead th {
top: 0;
position: sticky;
background-color: #666;
color: #fff;
z-index: 20;
min-height: 30px;
height: 30px;
text-align: left;
}
tr:nth-child(even) {
background-color: #f2f2f2;
}
th,
td {
padding: 0 5px;
font-name: Courier;
font-size: 12;
outline: 1px solid #ccc;
border: none;
outline-offset: -1px;
padding-left: 5px;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
tr {
min-height: 25px;
height: 25px;
}
* {
padding: 0;
margin: 0;
}
.fit {
/* set relative picture size */
max-width: 100%;
max-height: 100%;
}
.center {
display: block;
margin: auto;
}
.imgbox {
display: grid;
width: 100%;
}
.center-fit {
max-width: 100%;
max-height: 100vh;
margin: auto;
}
<!-- language: lang-html -->
<table>
<thead>
<tr>
<th colspan=2 style='text-align:center;font-weight:bold;'>&nbsp;Date/Time&nbsp;</th>
<th style='font-weight:bold;'>Author</th>
<th style='font-weight:bold;text-align:center;'>Mod</th>
<th colspan=2 style='font-weight:bold;'>Message</th>
</tr>
</thead>
<tbody>
<tr>
<td colspan=2 style='text-align:center;color:red;font-weight:bold;'>2023-05-14</td>
<td colspan=3 style='color:red;font-weight:bold;'>2023-05-14 This is where the livesteam title should be</td>
<td style='text-align:right;'><a href='https://youtu.be/dummy'>https://youtu.be/dummy</a></td>
</tr>
<tr>
<td style='text-align:right;color:Black;'>1&nbsp;R</td>
<td style='text-align:center;color:Black;'>07:21&nbsp;(1:14:21)</td>
<td style='text-align:left;color:Black;'>Some Watcher</td>
<td style='text-align:center;color:Black;'> (Mod)</td>
<td colspan=2 style='text-align:left;color:Black;'><a href="https://youtu.be/ddummy?t=4461" target="_blank">_</a>&nbsp;Thanks for the concert Brother</td>
</tr>
<tr class="dummy-row" aria-hidden="true">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>
<!-- end snippet -->
答案3
得分: 0
<td colspan=3 style='color:red;font-weight:bold;'>2023-05-14 这里应该是直播标题</td>
尝试将 colspan 属性改为 1,如下示例:
<td colspan=1 style='color:red;font-weight:bold;'>2023-05-14 这里应该是直播标题</td>
英文:
I think you have a typo in the next line:
<td colspan=3 style='color:red;font-weight:bold;'>2023-05-14 This is where the livesteam title should be</td>
Try to change the colspan attribute to 1 as the example below:
<td colspan=1 style='color:red;font-weight:bold;'>2023-05-14 This is where the livesteam title should be</td>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论