[英]How to make span look like img?
How can we make a span element as img element? 我们如何将span元素设为img元素? More precisely how can we do this, 更确切地说,我们如何做到这一点,
<span src='https://abs.twimg.com/emoji/v2/72x72/1f607.png'></span>
I saw this concept in twitter message bar when we put emoji in textarea. 当我们把表情符号放在textarea中时,我在twitter消息栏中看到了这个概念。 Thank you for you time and concideration. 谢谢你的时间和合作。 Kindly have a look I would be greatful. 请看看我会很高兴。
Edit-1 编辑-1
This question is not about using background image. 这个问题与使用背景图片无关。 Can we have other option like twitter people do. 我们可以有像twitter这样的其他选择。 This is what I saw in twitter page. 这是我在twitter页面中看到的。
<span class="RichEditor-pictographText" title="Smiling face with halo" aria-
label="Emoji: Smiling face with halo" data-pictograph-text="😇" data-
pictograph-image="https://abs.twimg.com/emoji/v2/72x72/1f607.png"> 
</span>
And these lines make an image look like and there is no background image as well. 这些线条使图像看起来像,也没有背景图像。
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 class='icon'></span>
A span
doesn't have an attribute where to assign an image, other than background-image
using the style
attribute, which won't size the span
to the image's size (like an img
does). span
没有使用style
属性分配图像的属性,而不是使用style
属性分配background-image
的属性,该属性不会根据图像的大小调整span
(就像img
一样)。
A possible workaround, using a custom attribute like data-src
, could be to use a script and insertRule()
, and add a pseudo class to the stylesheet. 使用data-src
等自定义属性的可能解决方法可能是使用脚本和insertRule()
,并将伪类添加到样式表。
var span = document.querySelector('span[data-src]'); var src = span.dataset.src; document.styleSheets[0].insertRule('span[data-src]::before { content: url('+src+'); }', 0);
span { border: 1px dashed gray; display: inline-block; }
<span data-src='https://abs.twimg.com/emoji/v2/72x72/1f607.png'></span>
Another possible way is to dynamically insert an img
into the span
. 另一种可能的方法是在span
动态插入img
。
When it comes to how Twitter does, I guess they use their custom attribute similar, for browsers (or readers) that simply doesn't support emoji's, like  
说到Twitter的工作原理,我猜他们使用类似的自定义属性,对于那些根本不支持表情符号的浏览器(或读者),例如 
and/or a custom font. 和/或自定义字体。
You can do something like this 你可以做这样的事情
#abc { background:url(http://t2.gstatic.com/images?q=tbn:ANd9GcQCze-mfukcuvzKk7Ilj2zQ0CS6PbOkq7ZhRInnNd1Yz3TQzU4e&t=1) left top; width:50px; height:50px; display: block; float: left; }
<span id="abc" class="abc"> </span>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.