In the dictionary responsive is defined as "Reacting quickly and positively", but for a website it is way more than just a reaction. When you open a website through a mobile device and the layout adapts to your screen resolution and the browsing experience is customized for the mobile environment, the website is using a responsive design. The practice of creating a responsive UI consists of a mix of dynamic grids and layouts, resizable images and a variety of UI elements. In a way, responsive design is the necessary evil for your website, because it can be very time consuming and expensive, but at the end of the day, the users are given a mobile environment they can browse with ease.
Let’s say you own an ecommerce website and you want your users to navigate quickly through your catalog. When they open your website from a mobile device they'll have to zoom in and out all the time in search for the product of their liking. They'll be lost in a world of small links, incorrectly sized images or menus. Here enters responsive web design.
Below you will find some of the basic, but key tactics and tricks that can help you get started on creating a responsive design and UI.
Prioritize your content.
Create a basic stencil of your design and decide what parts of the layout should be displayed first. The most popular pattern is surprisingly simple: a multi-column layout on a mobile device will have to stack it's columns below one another with little spacing between them.
But if you don't want a website that's a mile long, you can rely on
Off Canvas layouts. The key here is to hide the columns from the viewport and to move them to the side. When a control button is pressed or a swipe motion is initiated the columns are shown, creating the feeling that the user is in an app especially designed for his mobile device.
Define your resolutions.
Decide the kind of device you want to adapt the website for. If you want a Desktop/Tablet/Phone version of your website, a simple solution would be
adapt.js It is a simple JS plugin which allows you to use different stylesheets for different viewport sizes. The plugin works great with the
960 grid system , which distributes your content into columns and blocks that can help you maintain a stable layout throughout your website. The most common range definition used in adapt.js is:
range: [
'0px to 760px = mobile.css',
'760px to 980px = 720.css',
'980px = 960.css'
]
Design a UI that is easy to use.
On a mobile device a button will be easier to click than a text link, so make sure all of your important UI elements are properly sized for a finger and have enough spacing between them. Avoid using the CSS hover event for displaying elements like overlays or drop down lists, because on a touch device these events do not register properly. A simple and safer method would be to use jQuery to register the click and not the mouse enter event if the user is browsing through a mobile device. Detect if the user is browsing through a mobile device with this handy JS snippet.
if ( isMobile.any() ) {
$('.show').on({
click:function() { $(‘.hidden’).show(); }
});
} else {
$('.show').on({
mouseenter:function() { $(‘.hidden’).show(); }
});
}
Some tricks in the trade:
Give your elements a natural box-model with the box-sizing:border-box; CSS property. This is not highly needed for responsive design, but it will give you the perfect sizing model for an element, so nothing is added to your elements width if you increase the padding or the border. Further reading at the end.
Make your images resizable by setting their width in percentages. By setting max-width:100%; you will create an image that resizes relatively to its parent container, so when sized down the image will also rescale to fit in the container.
For a safe and agile layout, size your elements with percentages. A fluid element will be best viewed on different devices rather than an element with a static width.
div.full-width-box {
width: 96%;
margin-left: 2%;
margin-right: 2%;
}
Speed up your effects with hardware accelerated CSS properties. 3D CSS transform are the best way, not the safest though, for modifying your elements. A simple example would be hiding an element of the page when you use an Off Canvas layout. Combine that with a transition and you've got an even smoother experience.
div.hidden-column {
/* Add a transition */
transition:all linear 0.3s;
-webkit-transition:all linear 0.3s;
-moz-transition:all linear 0.3s;
/* Hiding the column from the viewport */
-webkit-transform: translate3d (-320px, 0, 0);
-moz-transform: translate3d (-320px, 0, 0);
-ms-transform: translate3d (-320px, 0, 0);
-o-transform: translate3d (-320px, 0, 0);
transform: translate3d (-320px, 0, 0);
}
div.hidden-column.visible {
/* Show the column when a class "visible" is added */
-webkit-transform: translate3d (10px, 0, 0);
-moz-transform: translate3d (10px, 0, 0);
-ms-transform: translate3d (10px, 0, 0);
-o-transform: translate3d (10px, 0, 0);
transform: translate3d (10px, 0, 0);
}
Now with jQuery we can add a class to that element when a control button is pressed.
$('.control-button').on({
click:function(){
$('.hidden-column').toggleClass('visible');
}
});
The above will cover only a handful of things you can achieve using fluid layouts, adapt.js and awesome CSS3 properties. Do not be afraid to exploit external resources or use already built layouts or grids. Some of the best articles and website that can help you get your foot through the door.
I hope we covered some of the basics for you, now go and put these advice to the test.