换行符替代文字 [英] Newline in alt text

查看:121
本文介绍了换行符替代文字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以在alt文本中为图片使用某种换行符,但仍遵守XHTML 1.0 Strict标准吗?



类似这样...

 < img src =foo.jpgalt =第1行\\\
Line 2/>

我在问,因为我想在我的网站上发布以下屏幕截图,但我想包括在搜索引擎优化原因和视力受损的替代文本的纯文本版本。



我更喜欢纯文本版本的截图,因为它看起来更具视觉吸引力。

解决方案

只需使用普通换行符。

 < img src =foo.jpgalt =第1行
第2行/>

Stack Overflow会在它们的标题中做到这一点:)

然后添加这个CSS:

  img {white-space:pre} 

演示: http:// jsfiddle .net / Madmartigan / S8SXP /


Can I use some sort of line break in the alt text for an image while still adhering to the XHTML 1.0 Strict standard?

Something like this...

<img src="foo.jpg" alt="Line 1\nLine 2" />

I'm asking because I want to post the following screenshot on my site, but I want to include the text-only version in the alt text for SEO reasons and for the visually impaired.

I prefer the screenshot over the plain text version because it looks more visually appealing.

解决方案

Just use a normal line break.

<img src="foo.jpg" alt="Line 1
Line 2" />

Stack Overflow does this in their titles :)

Then add this CSS:

img{white-space:pre}

Demo: http://jsfiddle.net/Madmartigan/S8SXP/

这篇关于换行符替代文字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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