Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/395.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何使span看起来像img?_Javascript_Jquery_Html_Image_User Interface - Fatal编程技术网

Javascript 如何使span看起来像img?

Javascript 如何使span看起来像img?,javascript,jquery,html,image,user-interface,Javascript,Jquery,Html,Image,User Interface,如何将跨度元素制作为img元素?更确切地说,我们如何才能做到这一点 <span src='https://abs.twimg.com/emoji/v2/72x72/1f607.png'></span> 当我们在textarea中添加表情符号时,我在twitter消息栏中看到了这个概念。 谢谢你的时间和协调。请看一看,我会很高兴的 编辑-1 这个问题与使用背景图像无关。我们可以像推特人一样有其他选择吗。这是我在twitter页面上看到的 <span class=

如何将跨度元素制作为img元素?更确切地说,我们如何才能做到这一点

<span src='https://abs.twimg.com/emoji/v2/72x72/1f607.png'></span>

当我们在textarea中添加表情符号时,我在twitter消息栏中看到了这个概念。 谢谢你的时间和协调。请看一看,我会很高兴的

编辑-1

这个问题与使用背景图像无关。我们可以像推特人一样有其他选择吗。这是我在twitter页面上看到的

<span class="RichEditor-pictographText" title="Smiling face with halo" aria-
label="Emoji: Smiling face with halo" data-pictograph-text="You can set it in a class background and add that class to the span

.icon {
  background: url("https://abs.twimg.com/emoji/v2/72x72/1f607.png") no-repeat;
  width: 100px;
  display: inline-block;
  height: 100px;
}

您可以在类背景中设置它,并将该类添加到span中

。图标{
背景:url(“https://abs.twimg.com/emoji/v2/72x72/1f607.png)无重复;
宽度:100px;
显示:内联块;
高度:100px;
}

您可以这样做

#abc
{ 
背景:url(http://t2.gstatic.com/images?q=tbn:ANd9GcQCze-mfukcuvzkk7ilj2zq0cs6pbokq7zhrinnd1yz3tqzu4e&t=1)左上;
宽度:50px;
高度:50px;
显示:块;
浮动:左;
}

A
span
没有用于指定图像的属性,除了使用
style
属性的
背景图像
,该属性不会将
span
的大小调整为图像的大小(就像
img
那样)

一种可能的解决方法是使用自定义属性,如
datasrc
,使用脚本和,并向样式表添加一个伪类

var span=document.querySelector('span[data src]');
var src=span.dataset.src;
document.styleSheets[0].insertRule('span[data src]:::{content:url('+src+');}',0)之前
span{
边框:1px灰色虚线;
显示:内联块;
}

元素在HTML中没有有效的
src
属性。但是使用javascript你可以用它做些什么呢?在twitter上,他们使用的是
数据
标记,而不是
src
<代码>数据象形文字图像=”https://abs.twimg.com/emoji/v2/72x72/1f62c.png“
@Gabriel是的,他们有。问题在于如何解决。谢谢您的回复@brk。我编辑了这个问题。编辑的零件中有更多详细信息。在这种情况下我们能做什么。。谢谢你的帮助。