html – 将图像放在文本块的中间

前端之家收集整理的这篇文章主要介绍了html – 将图像放在文本块的中间前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
如果不拆分字符串和仅使用CSS,是否可以实现以下效果

<img class="image-in-text" src="www.imgurl.com/img.png">
<span class="text-around-image">
    Text goes here
</span>

http://jsfiddle.net/s6hp92c4/

解决方法

是,

您可以使用浮动元素来下移浮动图像.

使用伪元素查看下面的演示:

body {
  font-family: sans-serif;
  font-weight: 300;
  line-height: 1.5em;/* set the unit to make sure it is applied in any browser */
}
div:before {
  content: '';
  padding-top: 3em;/* 2x 1.5em line-height */
  float: left;
}
img {
  float: left;
  clear: left;
  padding: 5px 10px 1px 0;
}
<div>
  <img src="http://fillmurray.com/88/88"/>
  <p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam,feugiat vitae,ultricies eget,tempor sit amet,ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est.
    Mauris placerat eleifend leo. Quisque sit amet est et sapien ullamcorper pharetra. Vestibulum erat wisi,condimentum sed,commodo vitae,ornare sit amet,wisi. Aenean fermentum,elit eget tincidunt condimentum,eros ipsum rutrum orci,sagittis tempus
    lacus enim ac dui. Donec non enim in turpis pulvinar facilisis. Ut felis. Praesent dapibus,neque id cursus faucibus,tortor neque egestas augue,eu vulputate magna eros eu erat. Aliquam erat volutpat. Nam dui mi,tincidunt quis,accumsan porttitor,facilisis luctus,metus</p>
</div>

http://jsfiddle.net/s6hp92c4/4/

原文链接:https://www.f2er.com/html/225859.html

猜你在找的HTML相关文章