简体   繁体   English

<p> 显示在 <img> 没有标签 <br>

[英]<p> is displayed under <img> tag without <br>

 <img src="http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/d1/d1a6cabea45b1f34f639b4f3dba8dd7af91072d4.jpg"><p>text 1</p>&nbsp;&nbsp;&nbsp;<p>text 2</p> 

My text1 and text2 are going under the image but I didnt use <br> tag. 我的text1和text2在图像下面,但是我没有使用<br>标签。
Is there any way to do this: 'img here' 'text1' 'text2' ? 有什么方法可以做到:'img here''text1''text2'吗? Thanks. 谢谢。

You can use Following css for this 您可以为此使用Following CSS

img, p {
    display:inline-block;
}

Just add this to your css 只需将其添加到您的CSS

 img{ display:inline; } p{ display:inline; } 
 <img src="http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/d1/d1a6cabea45b1f34f639b4f3dba8dd7af91072d4.jpg"><p>text 1</p>&nbsp;&nbsp;&nbsp;<p>text 2</p> 

CSS property called display:inline could be used ! 可以使用名为display:inline CSS属性!

 <img src=".."/>

 <p style="display:inline">text1</p>

 <p style="display:inline">text1</p>

It is better to always use a class and assign your styles to the class rather than to an element directly. 最好总是使用一个类并将样式分配给该类,而不是直接将其分配给元素。 This gives you better control over which element to apply a particular style to. 这样可以更好地控制将特定样式应用于哪个元素。

 .my-img,.text1,.text2 { display: inline-block; margin-right: 5px; } 
 <img class="my-img" src="http://cdn.akamai.steamstatic.com/steamcommunity/public/images/avatars/d1/d1a6cabea45b1f34f639b4f3dba8dd7af91072d4.jpg"><p class="text1">text 1</p>&nbsp;&nbsp;&nbsp;<p class="text2">text 2</p> 

Float is the right way to do this. 浮动是执行此操作的正确方法。

 img { float: left; padding-right:5px; } 
 <img src='http://placehold.it/220x220'> <p> Some text here. </p> <p> Some more text to follow. </p> 

And this is not only my opinion. 这不仅是我的观点。 A quote from w3schools : 来自w3schools的报价:

In its simplest use, the float property can be used to wrap text around images. 最简单的用法是,float属性可用于在图像周围包裹文本。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM