自动将图像尺寸调整为最大 TD 尺寸

时间:2021-05-26 14:54:30

标签: html css sharepoint html-table

我正在尝试解决 SharePoint 中的一个限制,该限制在其布局中只能有 3 列,而我需要四列。 因此,我创建了一个 2 列布局,并在每个单元格中添加了一个这样的表格。 我希望图像完全适合 TD。 如果您查看“Effort 1”前面的图像,它会调整到可用的高度。 我希望它完全适合单元格(例如“努力 3”前面的空单元格。

看起来它正在采用单元格 2 的当前高度并适合相同的大小。 但是,最大尺寸应该是“Effort 3”前面的空单元格,我希望图像完全适合其中(就像最后一张图像一样)。

<table style="width:100%;border:0;table-layout:fixed;word-wrap:break-word;border-collapse:collapse;" width="100 %">
    <tbody>
         <tr>
        <td width="100 %">
        <img align="center" width="100 %" src="/url/EmbeddedImage160142.jpg">
        </td>
        <td width="100 %"><h3>Effort 1</h3><p>A description of an effort and why it matters  </p>
        </td>
     </tr>
   </tbody>
  </table>

I tried various syntaxes. but the problem I have is that the image does not automatically resize to 

enter image description here

enter image description here

1 个答案:

答案 0 :(得分:1)

更正了代码中的一些错误,这就是解决方案。

<table style="width:100%;border:0;table-layout:fixed;word-wrap:break-word;border-collapse:collapse;" width="100 %">
    <tbody>
         <tr>
        <td width="50%">
            <img style="display:block; width:100%;" src="https://placeimg.com/100/100/any">
        </td>
        <td width="50%" style="vertical-align:top"><h3>Effort 1</h3><p>A description of an effort and why it matters  </p>
        </td>
     </tr>
   </tbody>
  </table>