http://www.sitepoint.com/understanding-responsive-web-design-cross-browser-compatibility/
In the last article, I described three ways to work with with images from a responsive design standpoint, discussing the B EST Solution to adopt while serving properly-sized imagery to a variety of the screen sizes. In today's article, I ' ll focus on imagery management from another point of view, which iscross-browser compatibility.
During the creation of a website-especially if your aim to make it structure responsive-one of the most important and Frequent problems that a web designer have to face involves cross-browser compatibility, which is, compatibility across DIF Ferent browsers.
What does ' compatibility ' stands for? The designer of a website must ensure that their design works properly and that it appearance is error-free and Functiona L on any platform used to view it. It ' s definitely one of the most complicated and frustrating aspects you must consider when designing a new project, but I T ' s essential that's the you don't leave anything to chance and keep cross-browser compatibility on mind throughout the DES IGN process.
Many of the new CSS capabilities introduced in the new CSS3 version is still not widely supported by all major browser S. In fact, some is not recognized and therefore ignored completely, which can pose major problems if your design relied On unsupported CSS. It ' s not just a variety of browser types either; different versions of the same browser can support (or fail-to-support) various design techniques, whic h complicates cross-browser compatibility even further.
Let's get back to image management, which probably are the weak point of the RWD approach, especially for browser Compatibi Lity issues. Photos and media need to being flexible and adapt to different devices, and at the same time, it's crucial that they don ' t SL ow down page loading in the process. Therefore, there is still no definitive, ideal solution to problems such as different screen sizes, restricted bandwidth ( In cases of mobile browsing), performance on high-resolution ("retina") displays, and so on.
It is clear that using a single image (the largest possible version) for all devices are not a advisable solution. Think about the time a poor smartphone-2g user would take to load your design. After your ultra-slow image loads, those high-resolution images would probably display at about one quarter of their origin Al size.
The largest problem is that media queries does not work with older browsers. Consequently, a responsive web page with many CSS3 rules applied can is seen correctly only by those who has RECENTLY-UPD Ated browsers with strong CSS3 support. Fortunately, there is three JavaScript solutions that can help us serve responsive websites to older browsers lacking CSS 3 support: respond.js, Modernizr, and adaptive.960.js. Let ' s has a look together.
Respond.js
The first solution is also the simplest one-i ' m talking about a script called respond.js, which enables the older browse R versions to understand and execute CSS3 media queries. Here's all it takes to get started.
1 |
<script type= "text/javascript" src= "js/respond.min.js" ></script> |
This script was called on the page (as shown above) and adds support to media queries, Min-width, Max-width, and all media Types (e.g. screen) for older browsers. This script can help your CSS3 instructions work properly and even for older browsers.
Respond.js may seem-like it's too easy-to-be-an-ideal solution, but if many projects this was an great solution because th E code is a read from the latest CSS3 PC browser and a browser designed for smartphones. The sole purpose of the script is to make older browsers read the CSS3 instructions within media queries. Nothing is more than nothing.
Modernizr
The second solution is the use of a tool called MODERNIZR. As explained in the documentation page of its website, "Modernizr are a small JavaScript library that detects the Availabil ity of native implementations for next-generation Web technologies, i.e. features so stem from the HTML5 and CSS3 Specif Ications. "
Many of these features is already implemented in at least one major browser (most of the them in the or more), and what Moder NIZR does is-very simply-tells you whether the current browser have this feature natively implemented or not. This was an indispensable tool, gives you fine control over the experience through Javascript-driven feature detection.
After the first phase of detecting features, MODERNIZR creates a JavaScript object with the results and adds classes to th e HTML element for the target with your CSS. It's a gorgeous solution, because it makes it easy-to-write conditional JavaScript and CSS to handle each situatio N, whether a browser supports a feature or not.
MODERNIZR supports these browsers:ie6+, Firefox 3.5+, Opera 9.6+, Safari, Chrome, Mobile Safari, Android WebKit Browse R, Opera Mobile, and Firefox Mobile.
You can download the full version of the library and implement it according to your specifications. However, if you are needs to test the compatibility of CSS3 in your browser, you can set the various options offered by T He library and create your own compressed code. Paste the code into a external. js file and include it at the tag of your HTML document. The MODERNIZR team recommend to include the library just after importing CSS.
You should has this code:
12345678 |
<!DOCTYPE html>
<
html xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
>
<
title
>Your title</
title
>
<
script type
=
"text/javascript" src
=
"modernizr-latest.js"
"></
script
>
</
head
>
<
body
>Your content</
body
>
</
html
>
|
Now there is a JavaScript library that indicates you whether the CSS3 or HTML5 functions you used is supported or not. Let the page run to the browser and look at the code with Chrome developer tools or Firebug.
You should see something as this:
123 |
< html class = "js flexbox canvas canvastext webgl no-touch geolocation postmessage websqldatabase no-indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage no-borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients cssreflections csstransforms csstransforms3d csstransitions fontface generatedcontent video audio no-localstorage no-sessionstorage webworkers applicationcache svg inlinesvg smil svgclippaths" > .... </ html > |
Adapt.960.js
The third solution that we consider are very different from the previous, especially because it does do use of CS S3 and accordingly of media queries. However, the concept is very similar to the CSS3 media queries.
If we use CSS3 with a single file, this library requires us to separate the code into several CSS files, one for each device Type. The library parses the resolution of the device and calls the CSS designed for that specific screen resolution.
We can download the script and see immediately how it works. Activate the library on your page with the following line:
1 |
<script type= "text/javascript" src= "js/adapt.min.js" ></script> |
Then, copy the following code:
1234567891011121314151617181920 |
<script type=
"text/javascript"
>
var ADAPT_CONFIG = {
// Where is your CSS?
path:
‘assets/css/‘
,
dynamic:
true
,
callback: myCallback,
range: [
‘0px to 760px = mobile.css‘
,
‘760px to 980px = 720.css‘
,
‘980px to 1280px = 960.css‘
,
‘1280px to 1600px = 1200.css‘
,
‘1600px to 1920px = 1560.css‘
,
‘1940px to 2540px = 1920.css‘
,
‘2540px = 2520.css‘
]
};
</script>
|
We See the list of CSS files within the ' range, ' one for each group of resolutions. Each of these files contains CSS properties related-a specific device, just as the code enclosed within the CSS me Dia queries.
The common css-that is the CSS this should apply to all screens sizes-should be included in a different CSS file, which for Convenience we can call master.css and retrieve it before the integration of this library, just like normal CSS File
1 |
<link href= "assets/master.css" rel= "stylesheet" type= "text/css" media= "screen" /> |
Conclusion
which of the three solutions should we adopt? They is all valid, sensible approaches. If you choose to apply the first solution (Respond.js), you'll have to write and manage a single CSS file, unlike adapt.96 0.js, which requires multiple CSS files. Finally, if you choose to try Modernizr, you'll take advantage of new CSS3 capabilities in the browsers so can support T Hem and still has easy and reliable means of controlling, the situation for the browsers, that cannot.
If you believe that, within few years, older browsers would be irrelevant and that mobile browsers would supersede their des Ktop counterparts, I believe that it's better to work with media queries and extend support for older browsers with Javas Cripts plugins that is available.
Remember that there is also web-based services to test a responsive website and simulate resizing of the browser window. These is responsive.is, which was very easy-to-use, and studiopress.com, which, after entering the web address, Mak Es different views of your website appear side-by-side.
In addition to web-based solutions, there is also applications that can is installed directly on your personal computer. Among them, we find Opera Mobile Emulator, which is available for Mac, Linux, and Windows. After installing and opening the application, you'll have a list of devices so it can emulate (with the unfortunate exce Ption of Apple devices).
To conclude this article, I ' d like to share a very useful online tool to test the compatibility of your live Website:cross Browsertesting.com. Must choose a operating system and a Web browser, and that's all. A series of well-organized screenshots on multiple browsers would allow you to having a complete view of the your site, and in th is, it'll be easier to understand on which elements you should modify to make your project perfectly compatible with Any platform.
Want to learn more about responsive Web Design? Check out SitePoint's new book, Jump Start Responsive Web design!
Understanding Responsive Web Design:cross-browser Compatibility