【问题标题】:Adding an image to right pushes the table below to right向右添加图像会将下表推到右侧
【发布时间】:2014-03-05 22:31:35
【问题描述】:

我有一些 HTML 代码。我添加了两张图片:一张在左边,一张在右边。然后它有两个标题和一个 HTML 表格。

问题是我使用以下代码将图像添加到文档中。

<img src="http://Path_To_Foler/Logo1.jpg" align="left" />       
<img src="http://Path_To_Foler/Logo2.jpg" align="right" />  

<p class="h1"><b>Private and Confidential</b> </p>
<p class="h1"><b>REPORT FOR Mr Person A BLA BLA</b> </p>

<table class="table" >
    <tr>
        <td class="CellHeader">Date </td>
        <td class="CellHeader">Time</td>
    </tr>
    <tr>
        <td class="cell"><AssessmentDateFrmMSPAPARR /></td>
        <td class="cell"><CurrentRcFrmMSPAPARR /></td>
    </tr>
</table>

CSS

  <style>
    .CellHeader{
        width:50%;
        text-align:left;
        font-family: 'calibri';
        font-size: 11pt;
        color:#FFFFFF;
        background-color:#151515;
        border:1px solid black;
        border-collapse:collapse;
    }
    .cell{
        width:50%;
        text-align:left;
        font-family: 'calibri';
        font-size: 11pt;
        border:1px solid black;
        border-collapse:collapse;
    }

    .table{
        width:100%;
        border:1px solid black;
        border-collapse:collapse;
    }
    .h1{
        page-break-before: always;
        text-align: center;
        font-family: 'calibri';
        font-size: 12pt;
    }
 <style>

问题

一切都按预期进行。当我添加第二张图片时,问题就开始了。添加第二张图片也会使表格右对齐。

当我从图像元素中取出align:"right" 属性时,表格是它应该在的位置,但是第二张图像被推到了右边,这是可以理解的。

我该如何解决这个问题?

【问题讨论】:

标签: html css image alignment


【解决方案1】:

尝试将align="left" 替换为style="float:left",将align="right" 替换为style="float:right"

然后,在您的 CSS 中将 clear: both 添加到 .table{} 中。

【讨论】:

  • 非常感谢您的快速回复以及所有试图为我的问题找到解决方案的人。这个解决方案就像一个魅力:)。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-26
  • 2023-03-19
  • 1970-01-01
  • 2020-05-25
相关资源
最近更新 更多