【问题标题】:Aligning images in HTML tables对齐 HTML 表格中的图像
【发布时间】:2015-08-08 09:32:46
【问题描述】:

我有一个 1x2 的 HTML 表格,它将作为电子邮件的标题。第一列包含链接图像,第二列包含标题。

        <table>         
        <tr>
            <td width="50%" style="text-align:left; padding-left:10%;">
                <a target="_blank" href="http://www.google.com/">
                    <img src="img/logo.jpg" alt="Logo" 
                    style="width:30%; height:30%;"
                     />
                </a>
            </td>

            <td width="50%" style="text-align:right; padding-right:10%;">
                <h2>Order Confirmation</h2>
            </td>
        </tr>
    </table>

如您所见,左侧单元格中的图像左对齐,右侧单元格中的标题右对齐,每个元素与边缘有 10% 的空间(填充)。

问题:我的图像尺寸被扭曲了!我将 img 的宽度和高度都设置为 30%,但它仍然失真。我猜这与桌子有关,但我无法弄清楚。告诉我!

ps:我必须为这个项目使用内联样式和表格。

【问题讨论】:

  • 您正在通过 css 在图像上设置相对大小,这意味着他们假设容器的宽度/高度为表格单元格的 30%...

标签: html css image alignment html-table


【解决方案1】:

如以下 SO {Resize image proportionally with CSS?}

中所述

您不应尝试同时限制两个尺寸,而只需将宽度设置为 30%,将高度设置为“自动”。试一试。

【讨论】:

    猜你喜欢
    • 2013-01-28
    • 1970-01-01
    • 2023-04-08
    • 2016-11-25
    • 1970-01-01
    • 1970-01-01
    • 2016-07-14
    • 1970-01-01
    • 2013-05-15
    相关资源
    最近更新 更多