Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
CSS Browser Selector + is a very small javascript which empowers CSS selectors; Best part - no more hacks, all compliant code; Cross-browser Mediaqueries-like (CSS3) helper - Alternative method of mediaqueries for developing responsive design for older browsers; You can now write code for - browser, browser version, platform, platform version, d…
JavaScript
branch: gh-pages
Failed to load latest commit information.
.idea ajustes documentação
css
img CSS Browser Selector V0.6.2
js Update css_browser_selector.js
tests testes corrigidos a maioria esta passando agora
.gitignore
.htaccess CSS Browser Selector V0.6.2
README.md Update README.md
crossdomain.xml
favicon.ico CSS Browser Selector V0.6.2
index.html Add a name space like `myns-webkit` to all class names by defining `v…
index_en.html Update index_en.html
index_pt.html Update index_pt.html

README.md

CSS Browser Selector +

A Cross-browser Responsive Design Helper

CSS Browser Selector + is a very small javascript which empowers CSS selectors.

http://ridjohansen.github.com/css_browser_selector/

See an example:

<html lang="pt-br" class="webkit chrome chrome25 win win8 js orientation_landscape minw_980 maxw_1199 no-hidpi datauri">
  • Best part

    • no more hacks
    • all compliant code
  • Cross-browser Media Queries like helper

    Alternative method of mediaqueries for developing responsive design for older browsers.

  • You can now write code for

    • browser
    • browser version
    • platform
    • platform version
    • device
    • device version
    • min-width and
    • max-width screen detection
    • orientation screen detection (landscape or portrait).
  • Optional namespace

    Add a name space like 'ns-webkit' to all class names by defining 'var css_browser_selector_ns = "ns-";' before loading script.

More info:
(http://rafael.adm.br/css_browser_selector)

beta/experimental versions:
(https://github.com/ridjohansen/css_browser_selector/)
(https://github.com/verbatim/css_browser_selector/)

Identifies

  • browsers: Firefox; IE; Opera; Safari; Chrome, Konqueror, Iron
  • browser versions: (most importantly: ie6, ie7, ie8, ie9)
  • rendering engines: Webkit; Mozilla; Gecko
  • platforms/OSes: Mac; Win: Win8, Win7, Vista, WinXP, Win2k, WinNT; FreeBSD; Linux/x11
  • devices: Ipod; Ipad; Iphone; WebTV; Blackberry; Android; J2me; RIM Playbook; mobile (generic)
  • enabled technology: JS (use in conjunction with <html class="no-js"> for even more granular control)
  • language detection

Recent contributors to 0.5, 0.6, 0.7:

Version History

  • v0.7 2013-04-01
    Add support to Hi-dpi displays Selector
    Add Pixel Ratio support for 1.5 and 2
    Add support to dataURI's Selector
  • v0.6.2 2012-09-10
    add new features for cross-browser development
    update the commons devices width (based on Twitter Bootstrap)
    improve continuously evaluates browser max-width and min-width (helper for mediaqueries-like screen width classes)
    improve continuously evaluates browser orientation (helper for mediaqueries-like orientation classes)
  • v0.6.1 2012-03-14
    iOS version detection
    beta: detect if being run in iPad app.
    (from: http://stackoverflow.com/questions/4460205/detect-ipad-iphone-webview-via-javascript)
  • v0.6.0 2012-01-24
    more detailed support for Opera, Chrome, Safari (and revised support for Firefox)
    versioning for Chrome, Blackberry, Android, Mac
    Android device detection
    altered how 'mobile' is deterimed to be added to the class string
    language detection
    RIM Playbook added
    continuously evaluates browser max width (in case of resizing)
    continuously evaluates browser orientation (portrait vs. landscape)
  • v0.5.0 2011-08-24
    any version of Firefox
    more versions of Windows (Win8 [tentative], Win7, Vista, XP, Win2k)
    more versions of IE under unique conditions
    if "no-js" in HTML class: removes and replaces with "js" (<html class="no-js">)

Resources

Other Versions

Example

Browser, Device, OS and Javascript detection

<style>
.ie .example { background-color: yellow; }
.ie7 .example { background-color: orange }
.gecko .example { background-color: gray; }
.win.gecko .example { background-color: red; }
.linux.gecko .example { background-color: pink; }
.opera .example { background-color: green; }
.konqueror .example { background-color: blue; }
.webkit .example { background-color: black; }
.chrome .example { background-color: cyan; }
.example { width: 100px; height: 100px; }
.no-js, .no_js, .nojs { display: block; }
.js { display: none; }
</style>

dataURI Selector

<style>
.datauri .example_bg {
    background-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC');
}
.no-datauri .example_bg {
    background-image: url('bg_default.png');
}
.datauri .img_default, .no-datauri .img_uri {
    display: none !important;
}
</style>

<div class="example_bg">
  <img class="img_uri" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABlBMVEUAAAD///+l2Z/dAAAAM0lEQVR4nGP4/5/h/1+G/58ZDrAz3D/McH8yw83NDDeNGe4Ug9C9zwz3gVLMDA/A6P9/AFGGFyjOXZtQAAAAAElFTkSuQmCC" alt="with dataURI" /> 
  <img class="img_default" src="img_default.png" alt="without dataURI" /> 
</div>

Hi-dpi and Pixel-Ratio Selector

<style>
.img_hidpi {
    display: none;
}
.no-hidpi .example_bg {
    background-image: url('bg_default.png');
}
.hidpi .img_default, .no-hidpi .img_hidpi {
    display: none !important;
}
.retina_1x .example_bg {
    background-image: url('bg_hidpi_1x.png');
}
.retina_2x .example_bg {
    background-image: url('bg_hidpi_2x.png');
}
.retina_2x .img_default, .retina_2x .x1 {
    display: none !important;
}
.retina_1x .img_default, .retina_1x .x2 {
    display: none !important;
}

or /* http://bjango.com/articles/min-device-pixel-ratio/ */

@media 
only screen and (min--moz-device-pixel-ratio: 1.5),
only screen and (-o-min-device-pixel-ratio: 3/2),
only screen and (-webkit-min-device-pixel-ratio: 1.5),
only screen and (min-device-pixel-ratio: 1.5) {
    .example_bg {
        background-image: url('bg_hidpi_1x.png');
    }
    .img_default, .x2 {
        display: none;
    }
}

@media
only screen and (-webkit-min-device-pixel-ratio: 2),
only screen and (   min--moz-device-pixel-ratio: 2),
only screen and (     -o-min-device-pixel-ratio: 2/1),
only screen and (        min-device-pixel-ratio: 2),
only screen and (                min-resolution: 192dpi),
only screen and (                min-resolution: 2dppx) { 
    .example_bg {
        background-image: url('bg_hidpi_2x.png');
    }
    .img_default, .x1 {
        display: none;
    }
}
</style>

<div class="example_bg">
    <img class="img_hidpi x2" src="img_hidpi_2x.png" alt="with pixel-ratio >= 2" />
    <img class="img_hidpi x1" src="img_hidpi_1x.png" alt="with pixel-ratio > 1 and < 2" /> 
    <img class="img_default" src="img_default.png" alt="with pixel-ratio 1 or default" /> 
</div>

Media Queries (Screen Width)

<style>
@media (max-width: 767px) {
.example {
border: 2px solid purple!important;
}
}
/* or */
.minw_0 .example, .maxw_767 .example {
border: 2px solid purple!important;
}

@media (min-width: 768px) and (max-width: 979px) {
.example {
border: 2px solid green!important;
}
}
/* or */
.minw_768.maxw_979 .example {
border: 2px solid green!important;
}

@media (min-width: 1200px) {
.example {
border: 2px solid orange!important;
}
}
/* or */
.minw_1200 .example {
border: 2px solid orange!important;
}
</style>

Media Queries (Orientation)

<style>
@media (orientation: landscape) {
.example {
border: 2px solid red!important;
}
}
/* or */
.orientation_landscape .example {
border: 2px solid red!important;
}

@media (orientation: portrait) {
.example {
border: 2px solid blue!important;
}
}
/* or */
.orientation_portrait .example {
border: 2px solid blue!important;
}
</style>

License

http://creativecommons.org/licenses/by/2.5/

Original Author

Rafael Lima http://rafael.adm.br

Based on idea by 37signals

http://37signals.com/svn/archives2/browser_selectors_in_css.php

Contributors

Something went wrong with that request. Please try again.