html - 为什么我的文字一直向下移动我的图像?

标签 html css

如何将我的“contenteditable”文本环绕在图像周围,同时防止图像在文本进入下一行时向下移动?

.note {
  width: 280px;
  height: 130px;
  margin-left: 25px;
  padding: 2;
  word-break: break-word;
  font-family: Note;
  font-size: 20px;
  z-index: 1;
}
<div class="note" contenteditable="true">Pellentesque pharetra mi lacus, vitae rhoncus nulla hendrerit vitae. Vestibulum nec lectus sed tortor maximus commodo.
  <span id='close' onclick='this.parentNode.parentNode.removeChild(this.parentNode)'>
    <img src="http://lorempixel.com/40/40/abstract/1/" height="30" width="30" align="right" style="vertical-align: top; float: right"/>
  </span>
</div>

最佳答案

将图像放在文本之前,然后应用 float:right 以允许文本围绕图像流动并将图像定位在右上角。

.note {
  width: 280px;
  height: 130px;
  margin-left: 25px;
  padding: 2;
  word-break: break-word;
  font-family: Note;
  font-size: 20px;
  z-index: 1;
}
#close {
  float: right;
}
#close img {
  width: 30px;
  height: 30px;
}
<div class="note" contenteditable="true">
  <span id='close' onclick='this.parentNode.parentNode.removeChild(this.parentNode)'>
    <img src="https://upload.wikimedia.org/wikipedia/commons/8/89/X-icon.png"/>
  </span>
  Pellentesque pharetra mi lacus, vitae rhoncus nulla hendrerit vitae. Vestibulum nec lectus sed tortor maximus commodo.
</div>

关于html - 为什么我的文字一直向下移动我的图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31820634/

相关文章:

html - 在两个 div 中拆分页面,当滚动时背景颜色不会填充两个 div 上的 100% 高度

javascript - 以 Shopify 的购买按钮为中心的问题

javascript - 刷新页面上的 Reste 动画 gif

javascript - 当下拉选择通过模型更改时如何触发jquery事件

javascript - JQuery 的 ajax 函数从 XML 中剥离 HTML 标签

css - 包含 <a href> 和 <span> 作为可点击链接的整个 <li> 元素

html - 如何在方向: column的 flex 容器中垂直放置图像

javascript - HTML/CSS 照片库不显示图片

html - 当鼠标悬停但不移动时,转换后的图像不会保持可见?

jquery - 在 Jquery 中将 Y 位置设置为 px