用表格替换 css flex

发布于 2025-01-14 02:55:43 字数 2666 浏览 3 评论 0原文

我正在使用 Flex 在报告上显示某些详细信息。但我发现电子邮件客户端不支持它,我认为它可以通过表格来实现。

这是我的代码。如何使用表格来获得相同的结果?具体来说,如果我们要使用表格,我们如何增加和减少单元格宽度?

    body {
        color: rgb(0, 0, 0);
        font-family: Helvetica, Arial, sans-serif;
        height: 100%;
        font-size: 14px;
    }
    
    div {
        display: block;
    }
    
    .divtable {
        border-top: 1px solid #eceff1;
        margin: 0 -16px;
        word-break: break-all;
    }
    
    .tablerow {
        border-bottom: 1px solid #eceff1;
        text-decoration: none;
        color: #000;
        display: flex;
    }
    
    .tablecol {
        line-height: 1.5em;
        padding: 10px 15px;
        flex: 1;
    }
    
    .bar {
        border-radius: 3px;
        background: #eee;
        display: inline-flex;
        width: 100%;
    }
    
    .text {
        display: inline-block;
        background: #04b;
        text-align: center;
        font-size: 12px;
        line-height: 18px;
    }
    
    .a {
        background: #28EB52;
    }
    .b {
        background: #F0FF0D;
    }
    <div class="divtable">
        <div class="tablerow">
            <div class="tablecol">Label</div>
            <div class="tablecol">
                <div class="bar">
                    <div class="text a" style="flex-grow: 8">8</div>
                    <div class="text b" style="flex-grow: 15">15</div>
                </div>
            </div>
        </div>
    </div>

我确实尝试过使用表格。我无法获得正确的宽度。有更好的方法吗?

(8 / (8+15)) x 100 = 34.7% (15 / (8+15)) x 100 = 65.3%

<table style="width:100%">
    <tr>
        <th style="width:25%">Label 1</th>
        <td style="text-align: center; background: #28EB52; width: 34.7%;">8</td>
        <td style="text-align: center; background: #F0FF0D; width: 65.3%;">15</td>
    </tr>
</table>
<table style="width:100%">
    <tr>
        <th style="width:25%">Label 2</th>
        <td style="text-align: center; background: #28EB52; width: 33.3%;">5</td>
        <td style="text-align: center; background: #F0FF0D; width: 33.3%;">5</td>
        <td style="text-align: center; background: #28EB52; width: 33.3%;">5</td>
    </tr>
</table>

I'm using flex to display certain details on a report. But I found that email clients are not supporting it and I see it can be achieved with tables instead.

This is my code. How do I use tables to achieve the same results? Specifically how do we increase and decrease the cell widths, if we are going to use tables?

    body {
        color: rgb(0, 0, 0);
        font-family: Helvetica, Arial, sans-serif;
        height: 100%;
        font-size: 14px;
    }
    
    div {
        display: block;
    }
    
    .divtable {
        border-top: 1px solid #eceff1;
        margin: 0 -16px;
        word-break: break-all;
    }
    
    .tablerow {
        border-bottom: 1px solid #eceff1;
        text-decoration: none;
        color: #000;
        display: flex;
    }
    
    .tablecol {
        line-height: 1.5em;
        padding: 10px 15px;
        flex: 1;
    }
    
    .bar {
        border-radius: 3px;
        background: #eee;
        display: inline-flex;
        width: 100%;
    }
    
    .text {
        display: inline-block;
        background: #04b;
        text-align: center;
        font-size: 12px;
        line-height: 18px;
    }
    
    .a {
        background: #28EB52;
    }
    .b {
        background: #F0FF0D;
    }
    <div class="divtable">
        <div class="tablerow">
            <div class="tablecol">Label</div>
            <div class="tablecol">
                <div class="bar">
                    <div class="text a" style="flex-grow: 8">8</div>
                    <div class="text b" style="flex-grow: 15">15</div>
                </div>
            </div>
        </div>
    </div>

I did attempt using tables. I'm unable to get the width's right. Is there a better way of doing this?

(8 / (8+15)) x 100 = 34.7%
(15 / (8+15)) x 100 = 65.3%

<table style="width:100%">
    <tr>
        <th style="width:25%">Label 1</th>
        <td style="text-align: center; background: #28EB52; width: 34.7%;">8</td>
        <td style="text-align: center; background: #F0FF0D; width: 65.3%;">15</td>
    </tr>
</table>
<table style="width:100%">
    <tr>
        <th style="width:25%">Label 2</th>
        <td style="text-align: center; background: #28EB52; width: 33.3%;">5</td>
        <td style="text-align: center; background: #F0FF0D; width: 33.3%;">5</td>
        <td style="text-align: center; background: #28EB52; width: 33.3%;">5</td>
    </tr>
</table>

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文