Responsive web design is no doubt a big thing now. If you still not familiar with responsive design, check out the list of responsive sites that I recently posted. To newbies, responsive design might sound a bit complicated, but it is actually simpler than you think. To help you quickly get started with responsive design, I've put together a quick tutorial. I promise you can learn about the basic logic of responsive design and media queries in 3 steps (assuming you have the basic CSS knowledge).
Step 1. Meta Tag (view demo)
Most mobile browsers scale HTML pages to a wide viewport width so it fits on the screen. You can use the viewport meta tag to reset this. The viewport tag below tells the browser to use the device width as the viewport width and disable the initial scale. Include this meta tag in the <head>.
<meta name="viewport" content="width=device-width, initial-scale=1.0">
Internet Explorer 8 or older doesn't support media query. You can use media-queries.js or respond.js to add media query support in IE.
<!--[if lt IE 9]>
<script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script>
<![endif]-->
Step 2. HTML Structure
In this example, I have a basic page layout with a header, content container, sidebar, and a footer. The header has a fixed height 180px, content container is 600px wide and sidebar is 300px wide.
Step 3. Media Queries
CSS3 media query is the trick for responsive design. It is like writing if conditions to tell the browser how to render the page for specified viewport width.
The following set of rules will be in effect if the viewport width is 980px or less. Basically, I set all the container width from pixel value to percentage value so the containers will become fluid.
Then for viewport 700px or less, specify the #content and #sidebar to auto width and remove the float so they will display as full width.
For 480px or less (mobile screen), reset the #header height to auto, change the h1 font size to 24px and hide the #sidebar.
You can write as many media query as you like. I've only shown 3 media queries in my demo. The purpose of the media queries is to apply different CSS rules to achieve different layouts for specified viewport width. The media queries can be in the same stylesheet or in a separate file.
Conclusion
This tutorial is intended to show you the basics of responsive design. If you want more in-depth tutorial, check out my previous tutorial: Responsive Design With Media Queries.
fsdsdfsdfsd
abcde…
This is exactly what I was looking for, and very concisely written. Thanks!
I have to still implement this on my website, but I am under research on whether to make the css unnecessary lengthy by including the css styles of all type of devices (all major 3-4 types) or make 1 general css and add addition for responsive styles and call based on devices. As these are two tricks used in recent trend.
Any suggestion?
If reply back.
How did you come up with these values? and Why max width 980 if the page wrapper is only 960?
@media screen and (max-width: 980px) {
#pagewrap {
width: 94%;
}
#content {
width: 65%;
}
#sidebar {
width: 30%;
}
}
thanks,
Glen
That’s usually used to ensure that the side room is not too narrow.
#pagewrap {
width: 94%;
}
#content {
width: 65%;
}
#sidebar {
width: 30%;
}
}
Exactly what I did today LOL
Bob
Awesome one.Blogger Tricks.
Many thanks for this tutorial!
Awesome clarification. this can be what makes bloggers such as you thus crucial to our internet development endeavors. Thanks!
I have only recently been getting in to responsive web design and im looking at using it on my new portfolio site im currently in the process of building (Work+Girlfriend seem to get in the way of this though :D)
Responsive web design is very important to my company and I, especially in this day and age. People are accessing websites on their phones more and more and instead of practically creating a whole new site, responsive design allows you to go from big monitors down to iPads and smart phones.
Check out my companies website for another example of responsive web design! http://www.cemahcreative.com – Web Development, Design & Consultation.
I first heard about Responsive Web Design when I saw Ethan Marcotte speak at the Future of Web Design 2010 conference in NYC.
It immediately made perfect sense to me and I have started to implement it in nearly all my projects.
Why build multiple designs to suit different resolutions and devices when you can do it one time?
Thanks for the article.
thanx, this is exact which i want about design
Thanks for this article and sharing your knowledge! Helps with understanding Responsive Design and getting it to work properly!
Nice introduction. It’s a great thing to learn responsive design. There’s foresight and can really help a business cater well to the market who aren’t anymore restricted by a stationary desktop.
Thanks for the easy-to-read tutorial. I was able to get it installed right away on my site.
My question for you is: how important is it to support browsers less than IE9? Aren’t we primarily talking about mobile browsing when we use responsive design? Are there many (any) smart phones running IE7, for example?
Thanks again!
Thank you for this great tutorial.
I work in a public school and am responsible for the school website. Right now I am using a template, buT i am experimenting with other designs on my own in the hopes of replacing it with something more user-friendly and fitting for our school. In the meantime, everything is switching to HTML5 and CSS3, but my district isn’t there yet. How do I adapt to responsive design using ASP and older CSS?
You could try javascript’s innerHeight/innerWidth properties to get the window size.
Thanks for the post…
We used to do stuff like that with Javascript long before CSS3
Nice post, thank you very much because that post, I will learn it when design my site^^
qwerty