Responsive web design is an approach for designing and developing a website so that the layout changes depending on the device/viewport on which the website is being viewed. The device could be a mobile phone, tablet, laptop, desktop computer, or even a smart TV. This type of design gives the best quality browsing experience.
Three key technical features are at the heart of responsive web design:
Truly responsive web design requires all three features to be implemented
CSS3 media queries go hand in hand with the flexible grid to make responsive web design work.
Luckily CSS3 is supported by many modern browsers.
For the purpose of making web sites responsive it can be said that the most important media feature is the “min-width”, this property allows us to apply specific CSS styles if the browser window (in pixels) drops below a particular width.
The main attributes of media queries are:
Some common Media Query settings for different devices: /* Smartphones (portrait and landscape) ----------- */ @media only screen and (min-device-width : 320px) and (max-device-width : 480px) {
/* Styles */
}
/* Smartphones (landscape) ----------- */
@media only screen and (min-width : 321px) {
/* Smartphones (portrait) ----------- */
@media only screen and (max-width : 320px) {
/* iPads (portrait and landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) {
/* iPads (landscape) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : landscape) {
/* iPads (portrait) ----------- */
@media only screen and (min-device-width : 768px) and (max-device-width : 1024px) and (orientation : portrait) {
/* Desktops and laptops ----------- */
@media only screen and (min-width : 1224px) {
/* Large screens ----------- */
@media only screen and (min-width : 1824px) {
/* iPhone 4 ----------- */
@media only screen and (-webkit-min-device-pixel-ratio : 1.5),
only screen and (min-device-pixel-ratio : 1.5) {
To allow mobile browsers to zoom in to your designs to fit them to the device width, add the following meta tag to the head section of your page:
<meta name="viewport" content="width=device-width" />
This itself makes your page instantly more responsive, as the width will automatically adjust to the width of the user’s device.
Other viewport settings include maximum-zoom and initial-scale.
maximum-zoom
initial-scale
Combining the CSS3 Grid with media queries creates a powerful solution for building fluid, responsive applications
Media queries are used to apply different grid styles depending on the screen width.
Here is a sample code for a 3 column layout:
HTML Part
<div class="section group"> <div class="col span_1_of_3"> This is column 1 </div> <div class="col span_1_of_3"> This is column 2 </div> <div class="col span_1_of_3"> This is column 3 </div> </div>
CSS Part
/* SECTIONS */
.section {
clear: both;
padding: 0px;
margin: 0px;
/* COLUMN SETUP */
.col {
display: block;
float:left;
margin: 1% 0 1% 1.6%;
.col:first-child { margin-left: 0; }
/* GROUPING */
.group:before,
.group:after {
content:"";
display:table;
clear:both;
.group {
zoom:1; /* For IE 6/7 */
/* GRID OF THREE */
.span_3_of_3 {
width: 100%;
.span_2_of_3 {
width: 66.1%;
.span_1_of_3 {
width: 32.2%;
/* GO FULL WIDTH AT LESS THAN 480 PIXELS */
@media only screen and (max-width: 480px) {
margin: 1% 0 1% 0%;
How it works
.section
This Splits up the page horizontally. You’ll need a few of these to break up the content, and you can use them in your main wrapper, or within other divs.
.col
This divides the section into columns. Each column has a left margin of 1.6% (around 20 pixels on a normal monitor), except the first one. Using .col:first-child { margin-left: 0; } means you don’t need to use class=”last” anywhere. It works in all browsers since IE6.
.group
It solves floating problems, by forcing the section to self clear its children (aka the clearfix hack). This is good in Firefox 3.5+, Safari 4+, Chrome, Opera 9+ and IE 6+.
.span_1_of_3
It specifies the width of the column. Using percentages means it’s 100% fluid.
@media queries
As soon as the screen size gets less than 480 pixels the columns stack and the margins disappear.
This feature allows you to adapt your images or other media to load differently depending on the device, either by scaling or by using the CSS overflow property.
Scaling in CSS is pretty simple to implement for both images and video. You can set the media element’s max-width to 100 percent, and the browser will make the image shrink and expand depending on its container. You should supply the image in the best quality and size possible and then let CSS adapt the image to the right size.
img, object {
max-width: 100%;
One of the major challenges in providing excellent responsive websites is the wide range of devices. It’s no longer possible to test your website on every one of these new devices. The idea is to use flexible and fluid layouts that adapt to almost any screen.
You must be logged in to post a comment.