最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

CSS非ASCII字符最佳实践_html/css

来源:动视网 责编:小采 时间:2020-11-27 15:57:34
文档

CSS非ASCII字符最佳实践_html/css

CSS非ASCII字符最佳实践_html/css_WEB-ITnose: 作者:zhanhailiang 日期:2014-10-30 问题场景 在写样式时经常需要用到非ASCII字符的属性值,如下: .hot_list .sign_discount:before { content: 满减; padding: 0 8px; margin-right: 7px; font-size:
推荐度:
导读CSS非ASCII字符最佳实践_html/css_WEB-ITnose: 作者:zhanhailiang 日期:2014-10-30 问题场景 在写样式时经常需要用到非ASCII字符的属性值,如下: .hot_list .sign_discount:before { content: 满减; padding: 0 8px; margin-right: 7px; font-size:


 作者:zhanhailiang 日期:2014-10-30

问题场景

在写样式时经常需要用到非ASCII字符的属性值,如下:

.hot_list .sign_discount:before { content: "满减"; padding: 0 8px; margin-right: 7px; font-size: 12px; line-height: 14px; color: #fff; text-align: center; background-color: #f13993; border-radius: 11px;}

但是Chrome下展示时有些时候会显示乱码:


除content外,font字体也是经常需要用于非ASCII字符的值,如font-family: “微软雅黑”

最佳实践

为避免以上这类编码问题,CSS推荐在涉及非ASCII字符时统一使用反斜杠转义以避免编码问题:

backslash escapes allow authors to refer to characters they cannot easily put in a document. In this case, the backslash is followed by at most six hexadecimal digits (0..9A..F), which stand for the ISO 106 ([ISO106]) character with that number, which must not be zero. (It is undefined in CSS 2.1 what happens if a style sheet does contain a character with Unicode codepoint zero.) If a character in the range [0-9a-fA-F] follows the hexadecimal number, the end of the number needs to be made clear.

详情请见:http://www.w3.org/TR/CSS2/syndata.html#escaped-characters

所以上例可以改成:

.hot_list .sign_discount:before { content: "\6ee1\51cf"; padding: 0 8px; margin-right: 7px; font-size: 12px; line-height: 14px; color: #fff; text-align: center; background-color: #f13993; border-radius: 11px;}

文档

CSS非ASCII字符最佳实践_html/css

CSS非ASCII字符最佳实践_html/css_WEB-ITnose: 作者:zhanhailiang 日期:2014-10-30 问题场景 在写样式时经常需要用到非ASCII字符的属性值,如下: .hot_list .sign_discount:before { content: 满减; padding: 0 8px; margin-right: 7px; font-size:
推荐度:
标签: html 字符 css
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top