笑脸“:)”在CSS中意味着什么?

本文翻译自:What does the smiley face “:)” mean in CSS?

I spotted this CSS code in a project: 我在一个项目中发现了这个CSS代码:

html, body { :)width: 640px;}

I have been around with CSS for a long time now but I never saw this ":)" code before. 我已经使用CSS很长一段时间了,但我之前从未见过这个“:)”代码。 Does it mean anything or is it just a typo? 这是什么意思还是只是一个错字?


#1楼

参考:https://stackoom.com/question/1ilEO/笑脸-在CSS中意味着什么


#2楼

It looks like a CSS hack to target IE7 and earlier browsers. 它看起来像是针对IE7和早期浏览器的CSS黑客攻击。 While this is invalid CSS and browsers should ignore it, IE7 and earlier will parse and honor this rule. 虽然这无效的CSS,浏览器应该忽略它,IE7和更早版本将解析并遵守这一规则。 Here is an example of this hack in action: 以下是此黑客行动的一个示例:

CSS CSS

body {
    background: url(background.png);
    :)background: url(why-you-little.png);
}

IE8 (ignores the rule) IE8(忽略规则)

例1  -  IE8

IE7 (applies the rule) IE7(适用规则)

例1  -  IE7

Note that it does not have to be a smiley face; 请注意,它不一定是笑脸; BrowserHacks mentions: BrowserHacks提到:

Any combination of these characters: 这些字符的任意组合:
! $ & * ( ) = % + @ , . / ` [ ] # ~ ? : < > |
[before the property name will work on] Internet Explorer ≤ 7 [在属性名称工作之前] InternetExplorer≤7


The GAH hot dog stand example is here . GAH热狗站的例子就在这里


#3楼

From an article at javascriptkit.com , that's applied for IE 7 and earlier versions: 来自javascriptkit.com上一篇文章 ,它适用于IE 7及更早版本:

if you add a non-alphanumeric character such as an asterisk ( * ) immediately before a property name, the property will be applied in IE and not in other browsers. 如果在属性名称之前添加非字母数字字符(如星号( * )),则该属性将应用于IE而不是其他浏览器。

Also there's a hack for <= IE 8 : 还有<= IE 8的黑客攻击:

div {
  color: blue;      /* All browsers */
  color: purple\9;  /* IE8 and earlier */
 *color: pink;      /* IE7 and earlier */
}

However that's not a good idea, they don't validate. 然而,这不是一个好主意,他们不会验证。 You always feel free to work with Conditional comments for targeting specific versions of IE : 您可以随时使用条件注释来定位特定版本的IE

<!--[if lte IE 8]><link rel="stylesheet" href="ie-8.css"><![endif]-->
<!--[if lte IE 7]><link rel="stylesheet" href="ie-7.css"><![endif]-->
<!--[if lte IE 6]><link rel="stylesheet" href="ie-6.css"><![endif]-->

But for those wanna see the hack in real, please open up this page in the latest version of IE you have. 但是对于那些想要真正看到黑客的人,请在最新版本的IE中打开这个页面 Then go to developer mode by doing a F12 . 然后通过执行F12进入开发人员模式。 In Emulation section ( ctrl + 8 ) change document mode to 7 and see what happens. 在仿真部分( ctrl + 8 )中将文档模式更改为7并查看会发生什么。

在此输入图像描述

The property used in the page is :)font-size: 50px; 页面中使用的属性是:)font-size: 50px; .

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值