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

如果不拆分字符串和仅使用CSS,是否可以实现以下效果?

enter image description here

<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/

相关文章
相关标签/搜索