从文本包装其他列的文本中停止使用100%宽度的HTML表列

发布于 2025-02-12 06:08:43 字数 694 浏览 2 评论 0原文

我有一个带有三列的HTML表(宽度为100%),宽度为100%。它可以正常工作,但是迫使左右列以文字包含其内容,即使屏幕上有足够的空间未包装。下图说明了我的问题。有足够的空间显示“南美”和第三列的整体,但中间的柱子迫使他们包裹。

这是代码:

<table style="width: 100%;" border="1">
<tr>
    <td>South America</td>
    <td style="width: 100%;">Green Beans</td>
    <td>$25,000 per kg</td>
</tr>
</table>

我不想nowrap,而表格:filex并不完美。有一个“适当的”技巧可以做到吗?

I have an HTML table (with 100% width) with three columns, the middle one with 100% width. It works fine, but it forces the left and right columns to text-wrap their contents, even if there is enough space on the screen to show them un-wrapped. The image below illustrates my problem. There is enough space to show "South America" and the third column whole, but the middle column forces them to wrap.

Wrapping Columns

Here is the code:

<table style="width: 100%;" border="1">
<tr>
    <td>South America</td>
    <td style="width: 100%;">Green Beans</td>
    <td>$25,000 per kg</td>
</tr>
</table>

I don't want to nowrap, and table-layout: fixed is not perfect. Is there a "proper" trick to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你在看孤独的风景 2025-02-19 06:08:46

使用Flexbox及其状态,以便您可以使用以下代码轻松解决问题,以满足您的要求。

table {
    width: 100%;
}

tr {
    display: flex;
}

tr td {
    width: 100%;
}
<table border="1">
    <tr>
        <td>South America</td>
        <td>Green Beans</td>
        <td>$25,000 per kg</td>
    </tr>
</table>

Use the Flexbox and its states so you can easily solve your problem using the below code to fulfill your requirement.

table {
    width: 100%;
}

tr {
    display: flex;
}

tr td {
    width: 100%;
}
<table border="1">
    <tr>
        <td>South America</td>
        <td>Green Beans</td>
        <td>$25,000 per kg</td>
    </tr>
</table>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文