仅使用HTML

时间:2015-06-09 11:13:36

标签: html css image alignment

我左边有一张图片,我希望右边的文字以图片为中心。我没有使用文本编辑器访问CSS,所以我只能用HTML格式化它。我试过了horizontal-align:middle,但它没有用。

这就是我所拥有的:

enter image description here

这是HTML代码:



<p style="text-align:justify">
  <strong>Pocket money</strong>
</p> 
<p style="text-align:justify">
  <img alt="" src="http://www.kangarooaupair.com/system/images/W1siZiIsIjIwMTUvMDYvMDgvMjIvNTcvMjAvMzA1L1BvY2tldF9tb25leS5wbmciXSxbInAiLCJ0aHVtYiIsIjEzNXgxMzUjYyJdXQ/Pocket-money.png" style="align:middle; float:left; height:42px; margin-right:5px; width:42px" />
</p> 
<p style="text-align:justify">Pocket money is usually between &euro;100 and &euro;120 per week.</p>
&#13;
&#13;
&#13;

有人可以帮帮我吗?

1 个答案:

答案 0 :(得分:0)

只需向包含该文字的height添加line-heightp即可快速完成。值与图像相同:42px:

&#13;
&#13;
<p style="text-align:justify">
  <strong>Pocket money</strong>
</p> 
<p style="text-align:justify">
  <img alt="" src="http://www.kangarooaupair.com/system/images/W1siZiIsIjIwMTUvMDYvMDgvMjIvNTcvMjAvMzA1L1BvY2tldF9tb25leS5wbmciXSxbInAiLCJ0aHVtYiIsIjEzNXgxMzUjYyJdXQ/Pocket-money.png" style="align:middle; float:left; height:42px; margin-right:5px; width:42px" />
</p> 
<p style="text-align:justify;height:42px;line-height:42px">Pocket money is usually between &euro;100 and &euro;120 per week.</p>
&#13;
&#13;
&#13;

但正如他们在评论中所说,如果您使用不同的结构(不一定是表格,而是表格样式:display:tabledisplay:table-cell),这可能会更好。

例如:

&#13;
&#13;
<p style="text-align:justify">
  <strong>Pocket money</strong>
</p> 
<div style="height:42px;display:table;">
  <div style="float:left;">
    <img alt="" src="http://www.kangarooaupair.com/system/images/W1siZiIsIjIwMTUvMDYvMDgvMjIvNTcvMjAvMzA1L1BvY2tldF9tb25leS5wbmciXSxbInAiLCJ0aHVtYiIsIjEzNXgxMzUjYyJdXQ/Pocket-money.png" style="height:42px; width:42px; margin-right:5px;" />
  </div> 
  <div style="display:table-cell;vertical-align:middle;">
    Pocket money is usually between &euro;100 and &euro;120 per week.
  </div>
</div>
&#13;
&#13;
&#13;