【问题标题】:How to place image without text alongside in html如何在html中放置没有文本的图像
【发布时间】:2018-04-08 15:03:36
【问题描述】:

我正在尝试通过修改一些现有的 html 来创建发票。我想在页面顶部放置一个图像(徽标),然后在其下方创建一个表格。我遇到的问题是,无论我做什么,表格中的文本都会出现在图像旁边。我已经找到了各种想法来将文本包裹在图像周围,但实际上没有任何想法可以不将文本包裹在图像周围。除了作为图像的标题,也不是我想要的。我的代码是:-

<style>
div.logo {float: right;}
table {width: 100%; table-layout: fixed;}
.twenty {width: 20%; }
.thirty {width: 30%; }
.fifty {width: 50%; }
</style>
<div class = "logo">
  <img align="right" src="https://cdn.shopify.com/s/files/1/1212/3100/files/logo.png?14279783622096777710" width="30%" height="30%"><br clear="all">
</div>
<table>
  <colgroup>
    <col class="fifty" />
    <col class="twenty" />
    <col class="thirty" />
  </colgroup>
  <tbody>
    <tr>
      <td></td>
      <td>Invoice Date</td>
      <td>{{ shop_name }}</td>
    </tr>
    <tr>
      <td></td>
      <td>Date {{created_at | date: "%d/%m/%y" }}</td>
      <td>{{ shop.address }}</td>
    </tr>
  </tbody>
</table>

非常感谢任何帮助。

我得到了什么Link to my invoice render

【问题讨论】:

  • 你想要的标志应该放在右侧,文字应该显示在左侧但低于标志高度。
  • 您希望布局是什么样的,例如右上角的徽标,下面的桌子全宽?
  • 尝试将徽标设为块元素,display:block 如果可行的话
  • 徽标应位于右上角,然后是整个宽度的下方表格。 3 列 50%、20% 和 30%。谢谢
  • 阅读了一些关于使用 display:block 的内容,但无法弄清楚将它放在代码或语法中的确切位置。无法让它工作。谢谢

标签: html css image html-table


【解决方案1】:

看起来您的代码没有任何问题,表格的第一列是空的,并且您有一个 colgroup.fifty 样式的 width: 50% 。这使它看起来像桌子被推到了右边。

在此处查看带有背景颜色的钢笔以使其更清晰:https://codepen.io/lauraeddy/pen/zPYKva

【讨论】:

  • 谢谢你,是的,我正在寻找这个布局。我知道我的第一个单元格是空的,但即使我在里面放了一些东西也不会改变任何东西。在原始问题的末尾附上了我如何呈现为链接的屏幕截图。
  • 请通过上面的链接查看更新的代码。我在图像 div 中添加了 width: 100%;。这还取决于您如何渲染代码,是通过打印还是在线系统?
  • 天才劳拉。那解决了它。它正在在线呈现为网页中的预览,因此不确定它周围可能会发生什么代码,我必须检查源代码。感谢您的帮助。
【解决方案2】:

如果你没问题,试试这个。图片将放置在 div 的中心。

<div class = "logo">
  <img align="right" src="https://cdn.shopify.com/s/files/1/1212/3100/files/logo.png?14279783622096777710" width="30%" height="30%"><br clear="all">
</div>

.logo {
    width: 100%;
    text-align: center;
    justify-content: center;
    display: flex;
}

<div class="table">
<table>
  <colgroup>
    <col class="fifty" />
    <col class="twenty" />
    <col class="thirty" />
  </colgroup>
  <tbody>
    <tr>
      <td></td>
      <td>Invoice Date</td>
      <td>{{ shop_name }}</td>
    </tr>
    <tr>
      <td></td>
      <td>Date {{created_at | date: "%d/%m/%y" }}</td>
      <td>{{ shop.address }}</td>
    </tr>
  </tbody>
</table>
</div>

.table {
    width: 100%;
    text-align: center;
    justify-content: center;
    display: flex;
}

【讨论】:

  • 我的猜测是,如果发票是可打印的,他将不得不在 print.css 中使用 flexbox 进行调整。
  • 我会在早上试一试。徽标想要正确对齐,但我想这只是意味着将 text-align 和 justify-content 更改为“正确”。谢谢
猜你喜欢
  • 2011-08-11
  • 1970-01-01
  • 2013-06-26
  • 1970-01-01
  • 2013-06-17
  • 2017-09-17
  • 2017-01-29
  • 2021-12-21
  • 1970-01-01
相关资源
最近更新 更多