如何设置< alt>字符串的字符样式标签? [英] How to style the string of an <alt> tag?

查看:122
本文介绍了如何设置< alt>字符串的字符样式标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法风格的alt?使用javascript?有伪属性?像这样:

Is there a way to style the alt? With javascript? With pseudo attributes? like this:

<img src="foo.jpg" alt="<h1>This is the caption</h1><p>This is some text</p><p>Another text</p>" />

使用JQuery框架)会有这样的效果吗?

And javascript (I use JQuery framework) does something like this?

Get value of <alt> from <img>
make value between <h1></h1> css font-size:22px; color:green;
make value between <p></p> css font-size:14px; color:black;

BTW:javascript读取图像的alt标签并在屏幕上显示。

BTW: The javascript reads the alt-tag of the image and shows them on the screen.. so this alt text will not only shown If the img isnt loaded.

推荐答案

这是 alt 属性,而不是标记,因此无法直接为其设置样式。它只是一个文本,如果图像无法加载显示。您可以设置< img> 元素的样式,并且它会影响大多数浏览器(但不是IE)中替代文字的样式。

It's the alt attribute, not tag, and it's not possible to style it directly. It's simply a piece of text that is displayed if the image fails to load. You can style the <img> element though and it will affect the styling of the alternative text in most browsers (though not IE).

如果您指的是在将鼠标悬停在某个图像上时出现在某些浏览器中的工具提示,则可通过 title 属性实现,并且适用于所有元素,而不仅仅是图像。 alt 属性也被IE用于图像上的此目的,但这不是标准。无论如何,标题工具提示不能样式。如果你需要fancier工具提示,你必须创建自己的。我想这里有很多这样的东西。

If you were referring to the tooltip that appears in some browsers when you hover over an image, that's achieved with the title attribute and works on all elements, not just images. The alt attribute is also used by IE for this purpose on images, but this is not standard. Either way, title tooltips cannot be styled. If you need fancier tooltips, you'll have to create your own. I imagine there's a plethora of such things out there.

这篇关于如何设置&lt; alt&gt;字符串的字符样式标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆