如何使用css水平并排对齐?

时间:2022-11-27 06:05:46

When i display below, the text 'Here is some text' is below the image - i want it to show to the right of the image?

当我在下面显示时,文字“这里有一些文字”位于图像下方 - 我希望它显示在图像的右侧?

<div style="width:50px;">
  <img src="http://assets.devx.com/MS_Azure/azuremcau.jpg" alt="blah" width="70" height="70" />
</div>

<div style="width:150px;">
  <h2>Here is some text</h2>
</div>

2 个解决方案

#1


1  

<div style="width:50px; display: inline-block;">
<img src="http://assets.devx.com/MS_Azure/azuremcau.jpg" alt="blah" width="70" height="70" />
</div>

<div style="width:150px; display: inline-block">
    <h2>Here is some text</h2>
</div>

changed float:left to display:inline-block. This is a better solution because it doesn't remove items from the document flow. Make sure you specify a width for every one though.

更改了float:left to display:inline-block。这是一个更好的解决方案,因为它不会从文档流中删除项目。确保为每个指定宽度。

#2


0  

<div style="float: left; margin-right: 10px;">
    <img src="http://assets.devx.com/MS_Azure/azuremcau.jpg" alt="blah" width="70" height="70" />
</div>
<div style="width: 300px;">
    <h2>Here is some text</h2>
</div>
<br style="clear: both;" />

This should work.

这应该工作。

#1


1  

<div style="width:50px; display: inline-block;">
<img src="http://assets.devx.com/MS_Azure/azuremcau.jpg" alt="blah" width="70" height="70" />
</div>

<div style="width:150px; display: inline-block">
    <h2>Here is some text</h2>
</div>

changed float:left to display:inline-block. This is a better solution because it doesn't remove items from the document flow. Make sure you specify a width for every one though.

更改了float:left to display:inline-block。这是一个更好的解决方案,因为它不会从文档流中删除项目。确保为每个指定宽度。

#2


0  

<div style="float: left; margin-right: 10px;">
    <img src="http://assets.devx.com/MS_Azure/azuremcau.jpg" alt="blah" width="70" height="70" />
</div>
<div style="width: 300px;">
    <h2>Here is some text</h2>
</div>
<br style="clear: both;" />

This should work.

这应该工作。