简体   繁体   English

HTML / CSS如何格式化文本并在其旁边浮动图像

[英]HTML/CSS How to format Text and have an Image floating next to it

Pretty rusty on my HTML and CSS skills, I've done this before at some point but forgotten how to do this. 我的HTML和CSS技能非常生锈,我之前曾经做过,但是却忘记了如何做。

I have text on the left side of the page, I want an image on the right side of this div next to it, floating there and not disturbing the text formatting. 我在页面的左侧有文字,我想在此div的右侧旁边有一个图像,该图像漂浮在该位置且不影响文本格式。

Text Description.....
Description..........
Description..........                             Image Goes About Here
Description..........
Description..........

Does anyone know how to do this off the top of their head? 有谁知道如何做到这一点? Thank you. 谢谢。

for example 例如
<style type="text/css">
#picture {
float: right;
}
#text {
margin-right: 110px;
}
</style>

edited 已编辑

The easy solution is to use display: inline-block to display information next to an image, without having to add inline css. 一种简单的解决方案是使用display:inline-block在图像旁边显示信息,而不必添加内联CSS。

img, p {
   display: inline-block;

}


<img src="image.png" />
 <p>
 text left
 </p>

use padding and float... 使用填充和浮动...

Ie

<div id="container">
  <div id="text" style="padding-right: <image-width+few px>">
     text text text
     text text text
  </div>
  <img src="<imagesrc" style= "float:right" />
</div>

padding so the text doesn't overlap with the image. 填充,使文本不与图像重叠。 this should give you the desired effect. 这应该给您想要的效果。 After the image, add a div with clear:both to return to use all the dims of the div. 在图像之后,添加带有clear:both的div以返回以使用div的所有暗淡效果。

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

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