简体   繁体   中英

Backslash in CSS padding shorthand declaration

The website Qq.com has a rule-set with two padding declarations which seem a bit strange. My question is, what does the 11px\\0 part do? Does this have something to do with overriding the first padding declaration? I understand the use of the slash in situations like these: / (forward slash) in css style declarations , but I have never seen something like this.

.suggestion .s_title {
padding: 3px 0 1px 11px;
padding: 4px 0 1px 11px\0;
color: #a0a3a8;
font-size: 12px;
line-height: 18px;
}

"Backslash zero" is a css hack targeting IE8 for the current rule. This can be a terrible thing to do, unless there is no other choices. What happens is that IE8 will erroneously believe that this is a valid rule to be applied while other browsers won't, leaving you with a chaos rule:

.my-dirty-rule-for-ie-8-only { margin-bottom: 5px\0; }

For this ruleset, that means the second padding will take effect by overriding the first one only if the user displays your page with IE8.

From a developper point of view, css hacks should be avoided at all cost. You seriously never want to deal with rules targeting a specific browser, as it will haunt you forever from the moment you fall for it.

As Harry pointed out, it was a IE specific hack. You use the \\0 part to specify the declaration for a specific IE version. More information about it here:

http://codemug.com/html/css-hacks-for-ie6ie7ie8ie9-and-ie10/ And here http://mynthon.net/howto/-/webdev/CSS-big-list-of-css-hacks.txt (See: 24. IE9 hack)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM