SlideShare a Scribd company logo
Css hacks for different browsers
A CSS filter is a coding technique used to hide or

         show CSS markup depending on the browser, version

            number, or capabilities. Browsers have different

         interpretations of CSS behavior and different levels of

            support for the W3C standards. CSS filters are

             sometimes used to achieve consistent layout
CSS        appearance in multiple browsers that do not have
Hacks?
                         compatible rendering.
The easiest way to target IE is with conditional comments. There is a

robust syntax that Microsoft has created to allow authors to do this. Here

          are two alternatives to parser CSS hacks only for IE:




                                       <!--[if IE 7]>
                                       <style type="text/css">
                                       </style>
                                       <![endif]-->

                                       <!--[if IE 6]>
                                       <style type="text/css">
                                       </style>
                                       <![endif]-->
The first hack targets only Firefox 1 and 2 by using the body:empty hack. The

 second hack, which is quite clever target all versions of Firefox by using the

 proprietary extension -moz. -moz combined with the -document url-prefix()

   which by the way is used by Firefox Addon creators targets Firefox and

   Firefox alone. By using proprietary extensions to CSS, as hacks, usually

means the most surefire way to target individual browsers without having to

           worry about another browser possibly parsing the CSS.

                                        /* Firefox 1 - 2 */
                                        body:empty #firefox12
                                        {
                                        color:blue;
                                        }

                                        /* Firefox */
                                        @-moz-document url-prefix()
                                        {
                                        #firefox { color:blue; }
                                        }
The Chrome CSS hack works similar to the Safari hack. By using the -webkit

  prefix we can target Chrome and Safari both as the both browsers have

                             similar features.




                                        /* Chrome and safari */

                                        body:nth-of-type(1) .chrome{
                                        color:#ff0000;
                                        }
                                        OR
                                        /* Chrome and safari */
                                        @media screen and (-webkit-
                                        min-device-pixel-ratio:0)
                                        {
                                        #safari { color:blue; }
                                        }
The Safari CSS hack works similar to the Firefox hack because it uses a

Safari proprietary extension to CSS. By using the -webkit prefix we can

                     target Safari and only Safari.




                                       /* Safari */
                                       @media screen and (-webkit-
                                       min-device-pixel-ratio:0)
                                       {
                                       #safari { color:blue; }
                                       }
                                        OR
                                       body:first-of-type(1) .safari{
                                       color:#ff0000;
                                       }
The Opera CSS hack works because of negation in CSS. This targets

ALL browsers that support -min-device-pixel-ratio that aren't -webkit. It

will only be a matter of time before Firefox supports this and this hack

              will then most likely apply to Firefox as well.




                                         /* Opera */
                                         @media all and (-webkit-min-
                                         device-pixel-ratio:10000), not
                                         all and (-webkit-min-device-
                                         pixel-ratio:0)
                                         {
                                         head~body #opera {
                                         color:blue; }
                                         }
CSS Hacks: different kinds



              Conditional comments are conditional statements interpreted by
               Microsoft Internet Explorer in HTML source code. Conditional
                comments can be used as a CSS hack by including links to

Conditional               stylesheets based on the layout engine.
comments




                CSS browser prefixes are a way for browser makers to add
                   support for new CSS features in a sort of testing and
               experimentation period. Browser prefixes are used to add new

 Browser       features that may not be part of a formal specification and to
              implement features in a specification that hasn’t been finalized.
  Prefixes
http://www.dynamicsitesolutions.com/css/filters/first-child-plus-html/



                  http://bgsserver.com/css-hacks/




Examples
Any questions?
Thank you

More Related Content

PPTX
MySQL Tips for WordPress
ODP
Making Chrome Extension with AngularJS
PDF
Advanced Chrome extension exploitation
PDF
Hacktivity2011 be ef-preso_micheleorru
ODP
Chrome extension development
PPT
Javascript(2)
PDF
Html5: something wicked this way comes - HackPra
PDF
Html5: Something wicked this way comes (Hack in Paris)
MySQL Tips for WordPress
Making Chrome Extension with AngularJS
Advanced Chrome extension exploitation
Hacktivity2011 be ef-preso_micheleorru
Chrome extension development
Javascript(2)
Html5: something wicked this way comes - HackPra
Html5: Something wicked this way comes (Hack in Paris)

Similar to Css hacks for different browsers (20)

PDF
HTML5 y CSS3
KEY
Stylesheets of the future with Sass and Compass
PPTX
Introduction to CSS3
PDF
Simply Responsive CSS3
PDF
CSS3: Ripe and Ready
PDF
Introdução a CSS
PDF
Accelerated Stylesheets
KEY
Better CSS with Compass/Sass
KEY
Compass/Sass
PDF
CSS3: Ripe and Ready to Respond
PPTX
Less css
PDF
Intro to CSS3
PDF
CSS3 Media Queries
PDF
Dreamweaver CS5.5でワークフローはどう変わるのか?
PPTX
Css 3
PPTX
Css 3
PDF
Introduction to Responsive Web Design
PPTX
The Basics of CSS3
PPTX
Website trends 2012 presentation
HTML5 y CSS3
Stylesheets of the future with Sass and Compass
Introduction to CSS3
Simply Responsive CSS3
CSS3: Ripe and Ready
Introdução a CSS
Accelerated Stylesheets
Better CSS with Compass/Sass
Compass/Sass
CSS3: Ripe and Ready to Respond
Less css
Intro to CSS3
CSS3 Media Queries
Dreamweaver CS5.5でワークフローはどう変わるのか?
Css 3
Css 3
Introduction to Responsive Web Design
The Basics of CSS3
Website trends 2012 presentation

Recently uploaded (20)

PPTX
Spectroscopy.pptx food analysis technology
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Electronic commerce courselecture one. Pdf
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
KodekX | Application Modernization Development
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Machine learning based COVID-19 study performance prediction
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
cuic standard and advanced reporting.pdf
PDF
Encapsulation theory and applications.pdf
PPT
Teaching material agriculture food technology
Spectroscopy.pptx food analysis technology
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Unlocking AI with Model Context Protocol (MCP)
Encapsulation_ Review paper, used for researhc scholars
Electronic commerce courselecture one. Pdf
Digital-Transformation-Roadmap-for-Companies.pptx
KodekX | Application Modernization Development
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Machine learning based COVID-19 study performance prediction
Per capita expenditure prediction using model stacking based on satellite ima...
The AUB Centre for AI in Media Proposal.docx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
cuic standard and advanced reporting.pdf
Encapsulation theory and applications.pdf
Teaching material agriculture food technology

Css hacks for different browsers

  • 2. A CSS filter is a coding technique used to hide or show CSS markup depending on the browser, version number, or capabilities. Browsers have different interpretations of CSS behavior and different levels of support for the W3C standards. CSS filters are sometimes used to achieve consistent layout CSS appearance in multiple browsers that do not have Hacks? compatible rendering.
  • 3. The easiest way to target IE is with conditional comments. There is a robust syntax that Microsoft has created to allow authors to do this. Here are two alternatives to parser CSS hacks only for IE: <!--[if IE 7]> <style type="text/css"> </style> <![endif]--> <!--[if IE 6]> <style type="text/css"> </style> <![endif]-->
  • 4. The first hack targets only Firefox 1 and 2 by using the body:empty hack. The second hack, which is quite clever target all versions of Firefox by using the proprietary extension -moz. -moz combined with the -document url-prefix() which by the way is used by Firefox Addon creators targets Firefox and Firefox alone. By using proprietary extensions to CSS, as hacks, usually means the most surefire way to target individual browsers without having to worry about another browser possibly parsing the CSS. /* Firefox 1 - 2 */ body:empty #firefox12 { color:blue; } /* Firefox */ @-moz-document url-prefix() { #firefox { color:blue; } }
  • 5. The Chrome CSS hack works similar to the Safari hack. By using the -webkit prefix we can target Chrome and Safari both as the both browsers have similar features. /* Chrome and safari */ body:nth-of-type(1) .chrome{ color:#ff0000; } OR /* Chrome and safari */ @media screen and (-webkit- min-device-pixel-ratio:0) { #safari { color:blue; } }
  • 6. The Safari CSS hack works similar to the Firefox hack because it uses a Safari proprietary extension to CSS. By using the -webkit prefix we can target Safari and only Safari. /* Safari */ @media screen and (-webkit- min-device-pixel-ratio:0) { #safari { color:blue; } } OR body:first-of-type(1) .safari{ color:#ff0000; }
  • 7. The Opera CSS hack works because of negation in CSS. This targets ALL browsers that support -min-device-pixel-ratio that aren't -webkit. It will only be a matter of time before Firefox supports this and this hack will then most likely apply to Firefox as well. /* Opera */ @media all and (-webkit-min- device-pixel-ratio:10000), not all and (-webkit-min-device- pixel-ratio:0) { head~body #opera { color:blue; } }
  • 8. CSS Hacks: different kinds Conditional comments are conditional statements interpreted by Microsoft Internet Explorer in HTML source code. Conditional comments can be used as a CSS hack by including links to Conditional stylesheets based on the layout engine. comments CSS browser prefixes are a way for browser makers to add support for new CSS features in a sort of testing and experimentation period. Browser prefixes are used to add new Browser features that may not be part of a formal specification and to implement features in a specification that hasn’t been finalized. Prefixes
  • 9. http://www.dynamicsitesolutions.com/css/filters/first-child-plus-html/ http://bgsserver.com/css-hacks/ Examples