简体   繁体   English

仅使用HTML左对齐图像

[英]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 &euro;100 and &euro;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 &euro;100 and &euro;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:tabledisplay: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 &euro;100 and &euro;120 per week. </div> </div> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 尝试使用align =“ middle”对齐html中的图像。 图像向左对齐 - Trying to align an image in html using align=“middle”. Image is being aligned to left 在不使用浮动的情况下将图像向左,中和右对齐 - Align image to left, middle and right without using float 3张图像的中间居中位置,左右图像与中间图像对齐 - Center middle of 3 images, left and right images align to middle image 表格单元格内容:在HTML中将文本的左上角和中间对齐 - Table cell content: align text top-left and image in the middle in HTML 在angularjs html中将图像向左对齐 - align image to left in angularjs html 使用跨度,文本对齐和内联块,CSS,HTML将文本左,中,右对齐 - Aligning text to the left, middle, right using span, text align, and inline-block, CSS, HTML 如何使用 css 和 html 对齐文本和图像? 左右位置? - How to align text and image using css and html ? left and right position? HTML img align=&quot;middle&quot; 不对齐图像 - HTML img align="middle" doesn't align an image 如何将div中的文本水平居中,左边的图像与垂直对齐的中间 - How to center text in the div horizontally with an image at left with vertical align middle 仅使用auto或%在中间对齐div内容 - Align div content in the middle using only auto or %
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM