[英]Align image middle left using HTML only
I have an image floating to the left, and I'd like to have the text on the right centered with the image. 我有一个图像浮动在左侧,我想使右侧的文本与图像居中。 I don't have access to the CSS as I'm using a text editor, so I can only style it in HTML.
我使用文本编辑器时无法访问CSS,因此只能用HTML设置样式。 I tried with
horizontal-align:middle
, but it doesn't work. 我尝试了
horizontal-align:middle
,但是它不起作用。
This is what I have: 这就是我所拥有的:
And this is the HTML code: 这是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 €100 and €120 per week.</p>
Can anybody help me please? 有人可以帮我吗?
You can do it quickly just by adding a height
and a line-height
to the p
that contains the text. 您只需在包含文本的
p
上增加一个height
和一个line-height
高就可以快速完成。 The values would be the same as the image: 42px: 这些值将与图像相同:42px:
<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 €100 and €120 per week.</p>
But as they said in the comments, this maybe be better if you used a different structure (not necessarily tables, but table styling: display:table
and display:table-cell
). 但是正如他们在评论中所说,如果您使用其他结构(不一定是表,而是表样式:
display:table
和display:table-cell
),则可能会更好。
For example: 例如:
<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 €100 and €120 per week. </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.