将图像右侧的两个文本行居中

时间:2016-04-12 14:25:46

标签: html css outlook electronic-signature

我试图将两个文本行对齐到图像中心旁边。我尝试了"vertical-align: middle;",但它不会将我的文字分成两行,如下所示: this is what I'm trying to achieve.

我的代码包括:

<p class="address">          
    <img class="logo" src="source" alt="">
    <span class="location">Line 1 of text</span>
    <span class="location_2"> Line 2 of text</span>
</p>

使用CSS代码:

p.address{font-family: Helvetica; font-size: 13px; color: #000000; margin-left: 0px;vertical-align:center;}
span.location{display: inline; }
span.location_2{display: block; }

我也尝试过这个解决方案:http://jsfiddle.net/hiral/bhu4p04r/7/ - 但它会在图片下显示文字。

图片为34x58px,我试图为Outlook html签名实现此目的。

我将尝试使用<div>容器,将<img>放入其中,然后放入<p>,如果它可以正常工作则不知道。

答案由LGSon给出阳性结果并进行了少量修改,例如:

    <table style="margin-bottom:5px; font-family: Helvetica; font-size: 13px; color: #000000;">
  <tr>
    <td>
      <img style="max-height:52px" src="img_source_here" alt="">
    </td>
    <td valign="middle" style="font-size:14px; margin-left: 10px;">
      Text 1<br>Text 2
    </td>
  </tr>
</table>

谢谢大家的帮助!

2 个答案:

答案 0 :(得分:5)

电子邮件通常更好地构建为表格,但CSS表可能有效:

img {
  min-width: 75px;
  height: 90px;
}
.columns {
  display: table;
}
.columns div {
  display: table-cell;
  vertical-align: middle;
  padding: 1em;
}
<div class="medium-12 columns">
  <div class="imgwrap">
    <img src="http://placekitten.com/g/75/90" class="left" />
  </div>
  <div class="text">1
    <br />2
    <br />3</div>
</div>

答案 1 :(得分:0)

如果您不知道哪些电子邮件客户端会打开您的邮件,我就会这样做。

&#13;
&#13;
<table style="font-family: Helvetica; font-size: 13px; color: #000000; ">
  <tr>
    <td rowspan="2">
      <img style="border: 3px solid #000" src="http://placehold.it/100" alt="">
    </td>
    <td valign="bottom">
      Line 1 of text
    </td>
  </tr>
  <tr>
    <td  valign="top">
      Line 2 of text
    </td>
  </tr>
</table>
&#13;
&#13;
&#13;