Passa al contingut principal

IE10 CSS Hacks

IE10 HacksLast year, Microsoft announced that IE10 will not be supporting conditional comments. With their history, this is obviously a risky move. Up to now, to target quirky behaviour in IE6-9, developers have been using conditional comments, conditional classes, and other IE-specific hacks.


But without conditional comments in IE10, the only options we’re left with to target CSS problems are hacks or browser sniffing — and we certainly don’t want to resort to the latter.


Interestingly, there have been a few posts and code snippets floating around that apparently do target IE10 specifically using a hack. Below is a summary of these three techniques, for reference.


Feature Detecting @cc_on


This interesting bit of code is discussed on this Reddit thread, and comes from someone named Rob W., who posted this code snippet on a StackOverflow thread.


The script is inside of an IE-excluding conditional comment to ensure that IE6-9 don’t recognize it, and then it feature detects something called @cc_on. Here it is:



<!--[if !IE]><!--<script>
if (/*@cc_on!@*/false) {
document.documentElement.className+=' ie10';
}
</script><!--<![endif]-->

This appends a class of “ie10” to the <html> element, similar to what conditional classes do. Then in your CSS, just use the “ie10” class:



.ie10 .example {
/* IE10-only styles go here */
}

I don’t know anything about this @cc_on statement, but it seems to work on my IE10 PP. Also, I would assume this would also work in IE11, so this hack might cause problems in the future.


And unlike the other two solutions in this post, this one’s actually reliant on JavaScript, so that’s another point against it.


JS Bin demo


@media -ms-high-contrast Hack


This one comes from a gist by German developer Alex Kloss. It takes advantage of two things: 1) The fact that IE10 supports media queries; and 2) The fact that IE10 supports -ms-high-contrast as a media query option, which IE9 doesn’t support.



@media screen and (-ms-high-contrast: active), (-ms-high-contrast: none) {
/* IE10-specific styles go here */
}

According to Alex, this targets IE10 in both high contrast and default mode, which will evidently cover all stable versions of IE10.


This hack doesn’t work in older Platform Preview releases, because it seems that -ms-high-contrast wasn’t supported in those. I can confirm that it doesn’t work in IE10PP2.


Also, as Alex points out in the comments on the gist, this will also target IE11, so again this may not be a great choice.


JS Bin demo


@media Zero Hack


Finally, this one will target both IE9 and IE10, but nothing else. Not exactly ideal, but it’s an option if you need it.


I don’t know who came up with this one, but it’s documented on Keith Clark’s blog.



@media screen and (min-width:0\0) {
/* IE9 and IE10 rule sets go here */
}

This one might eventually be the best choice, but maybe not at the moment. Eventually, IE9 users are supposed to get notified via Windows Update to upgrade to IE10. This is supposed to include Windows 7 users. If this happens (and I’m not holding my breath), eventually IE9′s market share will be taken over by IE10, the same way this happens with other browsers that auto-update.


And in addition to that, if this parsing bug is fixed in IE11, then that means it will also be future proof. But we won’t know until IE11 is released.


JS Bin demo


Concluding Warnings


Truth is, you shouldn’t have to use a CSS hack for a browser like IE10, or even IE9. Use a good CSS workflow and apply good principles when writing your code.


And in most cases when things differ, you should either be able to feature detect to fill in the gaps, or else use graceful degradation to allow acceptable experiences in IE10.


So take this post with a grain of salt and only use these hacks if you’re desperate and you’re on a tight deadline.


If anyone has any other info on these, or knows of any other ways to target IE10, comment and I’ll update accordingly.


Photo credit: Hacksaw on white from Bigstock



Related posts:



  1. How Do I Target IE7 or IE8 Using CSS Hacks?

  2. Dropping -ms- Vendor Prefixes for IE10

  3. Loading a Different jQuery Version for IE6-8








via Impressive Webs http://www.impressivewebs.com/ie10-css-hacks/

Comentaris

Entrades populars d'aquest blog

Learn Composition from the Photography of Henri Cartier-Bresson

“Do you see it?” This question is a photographic mantra. Myron Barnstone , my mentor, repeats this question every day with the hopes that we do “see it.” This obvious question reminds me that even though I have seen Cartier-Bresson’s prints and read his books, there are major parts of his work which remain hidden from public view. Beneath the surface of perfectly timed snap shots is a design sensibility that is rarely challenged by contemporary photographers. Henri Cartier-Bresson. © Martine Franck Words To Know 1:1.5 Ratio: The 35mm negative measures 36mm x 24mm. Mathematically it can be reduced to a 3:2 ratio. Reduced even further it will be referred to as the 1:1.5 Ratio or the 1.5 Rectangle. Eyes: The frame of an image is created by two vertical lines and two horizontal lines. The intersection of these lines is called an eye. The four corners of a negative can be called the “eyes.” This is extremely important because the diagonals connecting these lines will form the breakdown ...

El meu editor de codi preferit el 2024, que això ja se sap que va canviant 😄

Visual Code Visual Code és un editor de codi font lleuger, però potent que s’executa al teu escriptori i està disponible per a Windows, macOS i Linux. Compta amb suport integrat per a JavaScript, TypeScript i Node.js i té un ric ecosistema d’extensions per a altres llenguatges i entorns d’execució (com C++, C#, Java, Python, PHP, Go, .NET).  És una eina ideal per a desenvolupar i depurar aplicacions web i en el núvol. Per què Visual Code? Visual Code té molts avantatges com a editor de codi font, com per exemple: És gratuït, ràpid i fàcil d’instal·lar i actualitzar. Té un ampli ecosistema d’extensions que et permeten afegir funcionalitats i personalitzar la teva experiència de desenvolupament. Té un suport integrat per a molts llenguatges i entorns d’execució, i et permet depurar i executar el teu codi des del mateix editor. Té una interfície senzilla i elegant, amb diferents temes i modes de visualització. Té un sistema de sincronització de configuracions que et permet guardar les...

Las Mejores Aplicaciones Gratis para iPad de 2012

Las Mejores Aplicaciones Gratis para iPad de 2012 : ¿No tienes ni un duro? No te preocupes, pues hoy os traemos una extensa selección de las mejores apps gratuitas que puedes conseguir en la App Store para que llenes tu iPad de calidad, sin gastar nada de nada.   ¿Estás buscando juegos o apps gratis para tu iPad? En la App Store hay más de 500,000 apps y juegos, y una gran cantidad de ellos está disponible de forma totalmente gratuita. Aquí vamos con la selección de las mejores Apps gratis para iPad (todos los modelos), organizada por categoría. ¿Estás preparado? Las Mejores Apps Gratis de Redes Sociales para iPad Nombre Facebook Gratis Categoría Redes sociales Facebook es la red social más famosa del mundo , con casi mil millones de usuarios. Su app para iPad ha tardado, pero aquí está. Nombre Twitter Gratis Categoría Redes sociales Twitter es la red de microblogging por excelencia. La forma más rápida y directa de informar y mantenerse informado de las cosa...