html - 当文本达到我的 td 中图像的宽度时,如何在我的 td 换行中制作文本?

标签 html css html-table word-wrap

所以我有 <td>在我的表中看起来像这样:

<tr> 
    <td>
        <p class="tableText">Random text that goes on REALLY long..........</p>
        <img src="www.imageurl.com/img.png" width="33vw">
    </td>
    <td>
        <p class="tableText">Random text that goes on REALLY long..........</p>
        <img src="www.imageurl.com/img.png" width="33vw">
    </td>
</tr>

我想做的是每个 <td> 的宽度是 width的图像,那么当文本到达 width 时应该换行图像到下一行。然而,文本只是在运行。

我可以在 JS/JQuery、HTML 或 CSS 中做些什么来解决这个问题吗? (最好是 html/css)

最佳答案

只需在 p 中提供与 img 相同的 width,因为它们是 sibling 。

td {
  border: red solid
}
img {
  display: block;
  width: 33vw
}
p {
  width: 33vw
}
<table>
  <tr>
    <td>
      <p class="tableText">Random text that goes on REALLY long..........</p>
      <img src="//dummyimage.com/100x100" />
    </td>
    <td>
      <p class="tableText">Random text that goes on REALLY long..........</p>
      <img src="//dummyimage.com/100x100" />
    </td>
  </tr>
</table>

关于html - 当文本达到我的 td 中图像的宽度时,如何在我的 td 换行中制作文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37501670/

相关文章:

php - 跨多个网页的持久标题和侧边栏

javascript - 如何自动将 DIV 放入列中(未知数量的 DIV)

JavaScript - 使用 AppendChild() 将新行添加到表中

php - 为什么此 PHP 代码不提供给链接 TAG href 属性? (本地主机,不使用 laravel)

html - 如何在 HTML 中引用相对子域?

javascript - 如何获取用户输入的href值呢?

html - CSS 表格中出现奇怪的空白区域

javascript - 如何验证RadioButton选项?

html - 如何在 Bootstrap 中创建重叠的 div

python - 使用 BeautifulSoup 与基本表的选项 - 无类 ID,