繁体   English   中英

在HTML中插入图像而不会移动文本

[英]Insert image in HTML without shifting of text

我必须使用javascript在文字之间插入一个小图像。 当我插入图像时,文本随图像进入而右移。我想插入图像,以使文本不会移动或移位,并且图像会使用javascript叠加。 我当前的功能是

var paraId = android.selection.getParagraphID();
var range = window.getSelection().getRangeAt(0);
var selectionContents   = range.extractContents();
var span = document.createElement("span");
span.appendChild(selectionContents);
span.setAttribute("class","uiWebviewHighlight");
span.style.backgroundColor  = "blue";
span.style.color = "white";
var spanID = 'SP' + paraId;
span.setAttribute("id",spanID);
var image = document.createElement("img");
image.src = "http://www.google.com/intl/en_com/images/logo_plain.png";
image.height=5;
image.width=5;
image.align = "top";
image.style.position="relative";
span.appendChild(image);
range.insertNode(span);
<img src="test.png" style="float:right;">

你可以把float:left; 也有风格。

暂无
暂无

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

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