最小HTML / CSS为文本的每个字符指定不同的颜色 [英] Minimal HTML/CSS to specify distinct color for each character of the text

查看:935
本文介绍了最小HTML / CSS为文本的每个字符指定不同的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为HTML页面中的文本的每个字符指定不同的颜色。文本很长,生成的HTML文件大小应尽可能小。换句话说,使用的颜色格式标签应尽可能小。你建议如何执行此任务?

I need to specify a different color for each character of the text in an HTML page. The text is long and the generated HTML file size should be as small as possible. In other words, the color formatting tags used should be as minimal as possible. How do you suggest to perform this task?

推荐答案

您需要将每个字符包装在一个元素中,代码如

You need to wrap each character in an element, so it seems that the minimal code is like

<a style=color:#123456>x</a>

<font color=#123456>x</font>

代码长度相等,但在后者中,数字符号#在实践中可以省略(这是一个错误,省略它,但是通过浏览器实践和HTML5草稿,有错误处理有效地暗示,前提是该值不构成浏览器已知的颜色名称,这是有风险的,所以我会选择第一个。

for each character x. The codes are of equal length, but in the latter, the number sign '#' can in practice be omitted (it is an error to omit it, but by browser practice and HTML5 drafts, there is error handling that effectively implies the # provided that the value does not constitute a color name known to the browser. This is risky, so I would go for the first alternatively.

如果颜色实际上并不完全一样,但可以重复,那么使用

If the colors are not in fact all different but may repeat, then the use of

<a class=¿>x</a>

b

.¿{color:#123456}


$ b b

可能会导致更短的代码,然后你需要一个类名生成器;你可以保持类名为单个字符,但需要注意确保类选择器符合CSS语法。

could result in shorter code. You would then need a class name generator; you could keep the class names to single characters, but care would be needed to make sure that the class selectors will conform to CSS syntax.

这篇关于最小HTML / CSS为文本的每个字符指定不同的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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