浏览器hack总结 详细的浏览器兼容性解决方法
由于各浏览器对页面的解析不同,会导致页面在不同浏览器中显示的样式不一致,为了保持页面的统一,经常需要对浏览器进行兼容性问题的调试。
CSS Hack
面对浏览器诸多的兼容性问题,经常需要通过CSS样式来调试,其中用的最多的就是CSS Hack。所谓CSS Hack就是针对不同的浏览器书写不同的CSS样式,通过使用某个浏览器单独识别的样式代码,控制该浏览器的显示效果。CSS Hack主要分为两类
CSS 选择器Hack
CSS选择器Hack是指通过在CSS选择器的前面,加上一些只有特定浏览器才能识别的Hack前缀,来控制不同的CSS样式。针对不同版本的浏览器,选择器Hack分为以下几类:
(1)IE6及IE6以下版本识别的选择器Hack
书写CSS样式时,如果希望此样式只对IE6及IE6以下版本的浏览器生效,可以使用IE6及以下版本的选择器Hack,其基本语法如下:
* html 选择器{样式代码}
(2)IE7识别的选择器Hack
书写CSS样式时,如果希望此样式只对IE7浏览器生效,可以使用IE7识别的选择器Hack,其基本语法如下:
*+html 选择器{样式代码}
CSS属性Hack
这里小强老师,把属性hack分为 前缀属性hack和 后缀属性hack
CSS属性Hack(前缀) | 针对的浏览器 |
_color:red; | IE6及其以下的版本 |
*color:red ;或者 +color:red; | IE7及其以下的版本 |
CSS属性Hack(后缀) | 针对的浏览器 |
color:red\9; | IE6/IE7/IE8/IE9/IE10版本 |
color:red\0; | IE8/IE9/IE10版本 |
color:red\9\0; | IE9/IE10 |
color:red!important | IE7/IE8/IE9/IE10及其他非IE浏览器 |
其实,现在越来越的公司,不太让兼容ie6了,现在比较关心的是ie8.910等高版本的浏览器,因此这里小强老师也总结了ie专属hack ,比如ie8等。
选择器Hack写法 | 针对于的浏览器 |
@media screen\9{body { background: red; }} | 只对IE6/7生效 |
@media \0screen {body { background: red; }} | 只对IE8生效 |
@media \0screen\,screen\9{body { background: blue; }} | 只对IE6/7/8有效 |
@media screen\0 {body { background: green; }} | 只对IE8/9/10有效 |
@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {body { background: orange; }} | 只对IE10有效 |
如果样式比较多,条件注释,是不错的选择:
IE条件注释语句
IE条件注释语句 | 针对的浏览器版本 |
IE7 以下版本 | |
IE7及以下版本(包含IE7) | |
IE7 以上版本 | |
IE7及以上版本(包含IE7) | |
非IE7版本 | |
您使用不是 Internet Explorer | 非IE浏览器 |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The article discusses the HTML <progress> element, its purpose, styling, and differences from the <meter> element. The main focus is on using <progress> for task completion and <meter> for stati

The article discusses the HTML <datalist> element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

The article discusses the HTML <meter> element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates <meter> from <progress> and ex

This article explains the HTML5 <time> element for semantic date/time representation. It emphasizes the importance of the datetime attribute for machine readability (ISO 8601 format) alongside human-readable text, boosting accessibilit

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

The article discusses the <iframe> tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.
