• .NET Developer Tools DevTools

    UI controls for ASP.NET AJAX, MVC, WPF,
    Silverlight, Windows 8 and Windows Phone

  • Hybrid Mobile Development Icenium

    Cross-platform Mobile Development Tool
    with cloud-based architecture

  • HTML5 / JavaScript Development Kendo UI

    Everything you need to build sites and
    mobile apps with JavaScript and HTML5

  • Testing Tools TestStudio

    One easy tool for Functional, Performance,
    Load and Mobile software testing

  • Web Presence Platform Sitefinity CMS

    Everything for your online business - content
    management, ecommerce, emarketing

  • Agile Project Management TeamPulse

    Simple and intuitive project management
    and collaboration software

Contact us

We are here for you.
  • usa+1‒888‒365‒2779
  • uk+44‒20‒7291‒0580
  • bg+359‒2‒8099850
  • de+49‒89‒2441642‒70
  • au+61‒2‒8090‒1465
  • emailsales@telerik.com
Your account Access to your products, updates and support
Telerik Product Families
  • Your Account
    Your Account
    Log in
  • ABOUT US

    About Telerik

    • Company
    • Press Center
    • Customers
    • Community
    • Careers
    • Contacts
Kendo UI - The way of HTML5
Products ▼
Kendo UI Web Kendo UI Mobile Kendo UI DataViz Server Side Wrappers
Demos Purchase Download
Blogs Documentation
Support ▼
Premium Forums StackOverflow Forums
Resources ▼

Featured Resource

Kendo UI Dojo


Blogs Code Library Demos Documentation FAQ Testing
Premium Forums Roadmap User Voice Videos Webinars More Resources
Contact Us Search
 

Blogs

Responsive Design with Twitter Bootstrap

Tuesday, January 22, 2013 by Kendo UI Team Blog | Comments 16

Last week we looked at how Twitter Bootstrap is the perfect compliment to Kendo UI in that it helps you easily lay out your application while taking care of all the tricky CSS that may be happening under the covers. I created a sample 2 column application with a fixed header that allows a user to search the Rotten Tomatoes for movies.

The application looks great, but it has a serious limitation. It only really looks great at 940px. Yes, it technically works on tablets and phones, but it doesn't look very good and it's not usable with all the buttons and links being so small. We know that we can increase the reach of our application significantly if we do some things to help it function more like a mobile application at smaller sizes. To do that, we are going to be doing a little responsive design today.

Responsive Design

The term was originally coined by Ethan Marcotte in his article at A List Apart and later in a book on the same subject. Responsive design is fundamentally the concept of changing the way your application looks and behaves as the screen size gets smaller. This is done using CSS3 media queries.

Media Queries

Media query is a really fancy term for "conditional CSS rule". It simply apples some CSS based on certain conditions set forth. If those conditions are met, the style is applied.

Media queries are supported in IE9+ and pretty much every other browser, including mobile where they are particularly applicable. If you want to get simple Media Query support for IE7 and 8, you can use the popular Respond.js pollyfill.

Let's look at a simple media query to get started:

Simple media query

<style>
@media all and (max-width="1024") {
  h2 {
    color: green;
  }
}
</style>
<h2>My color changes when the width gets below 1024px</h2>

 

Media queries have two parts, a device specification and then a size rule. In the above, we are setting the following rule...

For all devices no matter what kind, if the width of the screen gets smaller than 1024px, make the h2 text color green.

Go ahead and check it out here for yourself if you are on a desktop where you can resize the screen. Just start resizing the browser window. Once you get below 1204px, the text will change colors. Notice that when you go back past 1024px in width, the style is no longer applied - and so effectively removed.

Making our application responsive

Twitter Bootstrap includes a response.css file which will take care of Bootstrap's stake in our little application's success. Go ahead and add that file to your application's header underneath the bootstrap link.

Include responsive design support for Bootstrap

<meta charset="UTF-8">
<title>Fixster Search</title>
<link href="css/kendo.common.min.css" rel="stylesheet">
<link href="css/kendo.bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-min.css" rel="stylesheet">
<link href="css/bootstrap-responsive-min.css" rel="stylesheet">

 

It will collapse the columns and then stack them on top of each other when the screen size gets small enough. But we are going to have to implement a few other items from the Bootstrap arsenal, as well as a few of our own media queries to get things looking just right.

The navbar

The navbar is currently not a problem for us because it doesn't contain very many items. For the sake of showing you how to deal with a small screen and a large header, I have added a few items to the navbar.

With the bootstrap-responsive CSS file, the navbar starts stacking the menu items on top of each other. When the screen gets real small, it's just a vertical list of items. This works, but it's far from ideal. We can handle this better using Bootstrap's Navbar toggle buttons.

The first thing that we need to do is wrap our unordered list of links in a div that has the nav-collapse class. This class will hide the list of links when the display gets too small to display them all horizontally.

Modify navbar to collapse links

...
<!-- wrap the list of header links in a nav-collapse class.
     this will hide the links when the browser width gets too small. -->
<div class="nav-collapse">
  <ul class="nav">
    <li>
      <a href="#">Home</a>
    </li>
    <li>
      <a href="#">Details</a>
    </li>
    <li>
      <a href="#">Settings</a>
    </li>
    <li>
      <a href="#">Profile</a>
    </li>
    <li>
      <a href="http://www.rottentomatoes.com">Rotten Tomatoes</a>
    </li>
  </ul>
</div>
...

 

We now need a way to display those links for smaller screens. Bootstrap provides a drop down menu where the links will magically appear if we just add a another element that will serve as the button to open said menu.

Add Menu Expand Button

<!-- this creates a button with 3 lines indicating that a menu is there
     if the button is pressed -->
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
  <span class="icon-bar"></span>
  <span class="icon-bar"></span>
  <span class="icon-bar"></span>
</a>
<!-- wrap the list of header links in a nav-collapse class.
     this will hide the links when the browser width gets too small. -->
<div class="nav-collapse">
  <ul class="nav">
    <li>
      <a href="#">Home</a>
    </li>
    <li>
      <a href="#">Details</a>
    </li>
    <li>
      <a href="#">Settings</a>
    </li>
    <li>
      <a href="#">Profile</a>
    </li>
    <li>
      <a href="http://www.rottentomatoes.com">Rotten Tomatoes</a>
    </li>
  </ul>
</div>

 

You can see this in action here. As you resize the width of the window, the links will disappear and the collapsed_headerbutton will appear. Clicking on the button will expand the content showing the links that were displayed horizontally when there was room enough to do so.

Now our navigation looks good, and the first column gets stack on top of the second when the window gets too small. That's an example of using some of Bootstrap's responsive capabilities.

 

The ListView

Our next order of business is to handle the Kendo UI ListView. As a starting point, let's see what it looks like full sized:

listview_full

The first thing that I notice as I start to collapse the page is that at around 980px, things start to look rather bad...

problem1

If you keep resizing, eventually the columns get stacked and the issue goes away. But as you resize down to phone width, it comes back again.

Note: I use a Chrome Plugin called Window Resizer which not only resizes your windows at set intervals, but also tells you what the current width of the browser window as as you resize it. I highly recommend this plugin.

In order to get rid of this problem, we need to do two things if there isn't enough room:

  1. Don't display the numbers between the pager buttons
  2. Hide the synopsis

Hiding the pager page list

We need to find out exactly what it is we need to hide to get the page numbers in the pager to go away. To do that, I'm going to be using the Chrome Developer Tools. I did a screencast on these recently. I can't urge you enough to become confident and comfortable with your browser's dev tools. If you don't like the dev tools that your browser has, find a browser that has some that you do like. You can always go back and test on your deployment target.

If I right-click the pager buttons, I can see that they are just an unordered list of items. That unordered list has a class of k-pager-numbers.

k-pager-numbers

We can hide the numbers by setting a style for the k-pager-numbers class that gives it display: none. We want to do the same thing on the synopsis. The synopsis will only be shown on larger screens. That makes media query look this this:

Media query to hide pages and synopsis

@media all and (max-width: 980px) {
  .k-pager-numbers, .synopsis {
    display: none;
  }
}

 

Now when we resize the window, the page numbers and synopsis go away when we are at smaller resolutions. Now the application fits perfectly to the window at any size.

no_pages_no_synopsis

 

But wait! We aren't done yet...

We still have a problem though. When I test the site on my iPhone, the application shows up and it's tiny. I have to pinch zoom to even be able to use and then scroll around. That's no good. What's happening here?

photo 1

By default, mobile devices zoom way out on content to display the whole page. This is so you see everything, and not just a portion of the page. This is how mobile devices ensure that all pages will at least be viewable. We just need to tell mobile devices that they don't need to make this auto-correction for us. To do that, we need to add the meta viewport tag.

Meta viewport tag

<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>Flixster Search</title>

 

All this does is tell our device to scale the content to 100% of it's actual size. And with that change, the application is now looking a whole lot better on phones!

photo 2

The finished product

Here is the finished application. I had to host it outside of JSFiddle as JSFiddle puts everything in an iFrame, thusly rendering my meta* tag useless.

Responsive design is not a silver bullet

Responsive design is such an attractive option. It allows you to build one application that reaches all users no matter what device they are on. However, responsive design can be very tricky. Media queries are incredibly powerful, but effectively implementing a solution is going to require some solid planning and execution. RD is a strategy, not a silver bullet.

For more examples of responsive design, head over to Six Revisions and checkout their 25 examples.

Kendo UI provides you with choices when it comes to mobile. You can use responsive design with Kendo UI Web, or you can specifically target mobile with Kendo UI Mobile. Both of these strategies are valid and effective, but each has its place depending on your requirements.

Make sure that you think "mobile first" when building your application. The days of delivering content on a desktop only are a thing of the past. Kendo UI gives you the tools to build first class web and mobile applications, no matter how you decide to do it.

About the Author
Burke Holland is a web developer living in Nashville, TN. He enjoys working with and meeting developers who are building mobile apps with jQuery / HTML5 and loves to hack on social API's. Burke works for Telerik as a Developer Evangelist focusing on Kendo UI. Burke is @burkeholland on Twitter.

16 Comments

  1. 1 Lars 22 Jan 2013
    Hi Burke,
    Thanks for this very informative post. Thought I'm wondering if we really need another plugin/library/framework to build a great website/webapplication with Kendo UI....is Frankenstein back? (means: why can't we make such things, for example responsive design, with KendoUI?)
  2. 2 Paul 23 Jan 2013
    Very nice :)  I wouldn't mind seeing something similar using Zurb Foundation...
  3. 3 Silvio Clécio 23 Jan 2013
    Very nice article, Burke.

    Thank you! :)
  4. 4 Vesselin Obreshkov 23 Jan 2013
    Really cool. I already adopted the Bootstrap theme. Next up is to do exactly this when we get to (re)doing our UI from mobile up.

    @Lars What do you mean by using the term Frankenstein? If you're afraid of using several different libraries to get the job done, maybe you should re-consider your career choice as a web developer. If you think one single framework can include everything and the kitchen sink and still work well, you must live in a different world than the rest of us. I personally would use Bootstrap all day long without the slightest worry. It's a very well written library, doesn't over-step any Kendo functionality and works great together. Absolutely no need for them to re-invent the wheel just so it's all in one huge library.
  5. 5 Lars 23 Jan 2013
    @Vesselin the term "Frankenstein" was introduced by KendoUI itself:

    "Kendo UI is everything professional developers need to build HTML5 sites and mobile apps. Today, productivity of an average HTML/jQuery developer is hampered by assembling a Frankenstein framework of disparate JavaScript libraries and plug-ins."
  6. 6 Burke 23 Jan 2013
    @Lars

    I think that you bring up a good point that there is a certain amount of overlap between Kendo UI and Bootstrap.  However one of our goals with Kendo UI was that we should never ever stop you from doing what you want to do.  Bootstrap is a very popular framework and we want to make sure that Kendo UI works with Bootstrap since using Bootstrap can provide some definite advantages specifically in terms of CSS layout.

    I can say that providing layouts and responsive Kendo UI widgets is "high" on our list for future implementation... :)
  7. 7 Ben 30 Jan 2013
    Since you're using Bootstrap, why not save yourself some typing and use its responsive utility classes (ie: .hidden-phone, .hidden-tablet) to hide the page numbers and synopsis?
  8. 8 Burke 31 Jan 2013
    @Ben

    That is a very good option as well and a nice way to automatically apply styles for devices.
  9. 9 Rob Levin 04 Feb 2013
    Thanks for sharing how you did responsive design with the bootstrap!
  10. 10 Nathan Prather 13 Feb 2013
    thanks for sharing!  I was wondering how well Bootstrap would play with Kendo UI so this clears it up...  

    I'd kinda of like to use it with Kendo Mobile as well but it probably doesn't make sense to...  I think I agree that if you can bake in Bootstraps concepts into Kendo Mobile/Web rather than requiring another library it would be nice...

    Thanks!
  11. 11 Shaun Peet 14 Feb 2013
    +1 for a similar concept using Foundation instead.  And since there is a "bootstrap theme" for KendoUI, a "foundation theme" would also be nice.

    IMO the navbar in Foundation is both easier to construct/maintain and when it collapses the use of the screen by having animations is much better.

    Also having a look at the latest blog posts from the Bootstrap folks (laced with profanity) compared to the polished professionalism from the Zurb guys, I'm sure I'm not the only one getting turned off by (formerly Twitter) Bootstrap.
  12. 12 Julie Setbon 18 Feb 2013
    + 1 for Zurb Foundation 4.0 (mobile first framework about to come out this month)
  13. 13 Jaz Lai 20 Feb 2013
    Hmm it looks like your blog ate my first comment (it was extremely long) so I guess I'll just sum it up what I wrote and say, I'm thoroughly enjoying your blog. I too am an aspiring blog blogger but I'm still new to the whole thing. Do you have any tips for inexperienced blog writers? I'd definitely appreciate it.
  14. 14 Dale 18 Mar 2013
    IE9 on W7, I get three vertical scrollbars running the sample at http://jsfiddle.net/burkeholland/rmUgV/embedded/result/.
    Is the sample not well thougth out or is this just not ready for prime time?
  15. 15 Burke 03 Apr 2013
    @Shaun

    I haven't checked out Zurb, but I've heard some really good things about it.  I suppose that it's high time I took a look at how Kendo UI plays with their grid system.
  16. 16 Joshua 13 May 2013
    @burke,
    It would have been nice if you did this example with the Grid control which in my opinion is the most used of all the data presentation controls.
    if this was done with the Grid control, what would you have done differently to make it responsive or is it just hiding the page numbering too.
     

Comment

  1. Click to add

  2. Click to add

  3. Click to add

  4.    
     
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
    •  
     
      
       
Blogs feed
Categories

  • Tutorials (26)
  • Release (33)
  • Browsers (7)
  • Extensions (3)
  • Tip of the Week (10)
  • Videos (5)
  • Concepts and Theory (13)
  • Misc. (25)
  • Framework Constructs (6)
  • Mobile (6)
  • UI Widgets (5)
  • Blogs (1)
Archive
  • 2013 May (6)
  • 2013 April (10)
  • 2013 March (9)
  • 2013 February (12)
  • 2013 January (10)
  • 2012 December (9)
  • 2012 November (11)
  • 2012 October (6)
  • 2012 September (7)
  • 2012 August (8)
  • 2012 July (10)
  • 2012 June (8)
  • 2012 May (10)
  • 2012 April (7)
  • 2012 March (13)
  • 2012 February (10)
  • 2012 January (6)
  • 2011 December (10)
  • 2011 November (4)
  • 2011 October (6)
  • 2011 September (5)
  • 2011 August (9)
Home Web Mobile DataViz Server Wrappers Whitepapers Surveys Chrome Icenium Contact Us

Kendo UI framework is developed by Telerik - a leading provider of UI components for web, desktop and mobile applications. Trusted by over 100,000 customers worldwide for our devotion to quality and industry-best technical support, Telerik helps professionals maximize their productivity and "deliver more than expected" every day.

kendoui - powered by html5, css3 & jquery
get social
  • Twitter
  • Facebook
  • Google plus
  • RSS
Privacy Policy | Branding Guidelines
Powered by Sitefinity CMS

Copyright © 2011 - 2013 Telerik Inc. All rights reserved.