Responsive Web Layouts for Mobile Screens: Intro, Tips and Examples |
- Responsive Web Layouts for Mobile Screens: Intro, Tips and Examples
- A Look Into: CSS3 :First-Of-Type Structural Selector
- How To Assign Shortcuts to Any Program in Windows [Quicktip]
Responsive Web Layouts for Mobile Screens: Intro, Tips and Examples Posted: 16 Jul 2012 05:14 AM PDT Editor’s note: Welcome to our first theme-based series which will run on Hongkiat.com for the following two weeks. We’re kicking off our "Responsive Web Design 10-part series" with an intro into why you should be building responsive web layouts for mobile. Designers have it tougher now than before. We not only have to design for stationary devices, but also mobile devices like the tablet and smartphones, and since we are talking about a lot of different screen sizes and resolutions here, it’s a huge task to shoulder. In light of this, responsive web design could be the best solution. It offers more than just a simple mobile template; instead, your entire site layout is designed to be flexible enough to fit into any possible screen resolution. With such a fluid design scheme there are obvious benefits and drawbacks. Consider my examples below for how responsive web design can make the transition into mobile devices a smoother one. How Responsive Design WorksWhen I use the word “responsive” in terms of web design I mean that the entire layout responds based on the user’s screen resolution. Imagine this scenario: you’re reading a website on one tablet, then you switch to another device for one reason or another. The browser window is now re-sized. A responsive web design layout will feature schemes and a layout that gracefully breaks down and reinvents itself. From a usability perspective this is a brilliant technique. Responsive design is all about creating a homogeneous experience regardless of the browser or device screen size. I’ve found the perfect example from ‘A List Apart’ to illustrate my point, which also includes dynamic images. The width is set in CSS using percentages for mostly all of the internal container elements. Larger websites also respond well to removing dynamic content such as JavaScript when it’s not supported. Why Design for Mobile?It has become evident that more users are going mobile, and not just for on-the-go web browsing either. Tablet PCs have begun to change in context when users are online in the classroom. Designing for mobile is certainly a requirement in modern day web standards. The only problem is choosing your method of development, and targeting your audience appropriately. When you start coding for specific screen resolutions you end up with too many stylesheets to deal with. Media queries in CSS3 can be used to build iPhone-specific layouts for both portrait and landscape view. Since you can predetermine the pixel density it’s easy to revamp any HTML template for mobile.
But when you code a layout for responsive design the mobile aspects are taken care of by default. Both desktop and mobile users will be offered a similar experience and you won’t need to worry about external CSS properties. The only research you’d need to perform is planning for the smallest possible display screen. Google Analytics traffic data can be very helpful for this. You won’t likely get your website working 100% on every single device running every browser. But you can target a majority based on the average width of the screen. Older iPhone models use a 320×480 display resolution which isn’t so unbelievable. I would shoot for a minimum width of 240px, or even smaller if you can fit it. Removing the Default ZoomIf you have spent any time browsing the Web on a smartphone you’ll notice how websites are scaled out to fully display within the screen. This is for the user’s convenience since most websites do not have a mobile counterpart, thus the full layout is the safest bet. But when you get into building a responsive mobile design, the auto-zoom can really mess up your layout elements. Specifically, images and navigation content may appear small or too large in your layout. There is a special meta tag you can append into the document header which resets this in most Android and iPhone devices. <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;" /> This is known as the viewport meta tag which sets up some custom variables within the content. Apple has a documentation page regarding a few other meta tags you should look into, although these are geared specifically toward websites on iOS. The initial-scale value is important as this defaults your website to a full 100% zoom. The last value for user-scalable will remove this zoom functionality altogether so the user cannot resize the layout. This will lock the design into one size based on the full device width. Note that even if you disable the zoom functionality a good responsive design will still adapt when transitioning from portrait to landscape on any device! But it makes sense to lock a responsive design and remove the generic scaling options. Dynamic Image ScalingImages are another important facet of practically every website. Mobile users may not be looking to stream videos, but photos are a whole different story. These are also the biggest culprits when it comes to layouts breaking out of the box model. img { max-width: 100%; } The standard rule for CSS is to apply a max-width property to all images. Since they’ll always be set at 100% you will never notice distortions. When the user re-sizes their browser window smaller than your image can handle it’ll automatically re-adjust to 100% width scaled down. The problem is that Internet Explorer cannot understand this property, so you’ll need to put together an IE-specific stylesheet using width: 100%;. Flexible images are also possible if you use JavaScript or jQuery plugins. There are some really smart developers out there who have put in the time to build incredibly responsive image content. This thread is just one of many in Stack Overflow which features an outlandish yet convenient approach to solving the IE6/7 bugs. I would personally recommend sticking to natural CSS image resizing. If your website is running in a mobile browser with JavaScript enabled it can most likely support CSS as well. If you really want to dig deeper, check out this 24 ways article Images for Adaptive Designs.. Touching DesignsWeb developers may forget that mobile users aren’t on keypad phones like BlackBerrys anymore. A majority of smartphones today use touchscreen interfaces, which render a scenario different from mouse-and-keyboard setups. As such you’ll need to consider alternate solutions in mobile elements. Dropdown menus may work better when displayed as a single menu on the right-hand side. Most users are able to tap links on the right side easier than the left, but either column works to alleviate space. Using margin indents, it’s simple to identify the link hierarchy without requiring any jQuery code. It’s also good practice to increase the size of these navigation links. Mobile users do not have the luxury of a large screens afforded on desktops or even laptop computers. You need to keep text large, up-front, tap-able and readable at all costs. You may even want to resize if the user switches between portrait and landscape view – a fairly common recurrence when browsing the mobile web. Custom CSS LayoutsIn general it’s best to adapt your layout and allow for natural degradation of your content. If you have a sidebar and content area you should set them in widths of percentages or ems, anything that will re-size with the browser window. If you apply a min-width this will eventually break off part of the layout; so now your sidebar content displays above the page content.
When you consider how this affects the overall design it’s a lot easier to develop external stylesheets. However you are likely to run into screen resolutions which are just too small for your layout to render. This is the perfect scenario for adding custom CSS properties to remove portions of the page, or reformat the content altogether. Toggle Extra Content On/OffExamples of large content blocks include web forms, dynamic menus, image sliders, and other similar ideas. Instead of completely removing these elements as the layout gets smaller why not simply hide them in a “minimized” content div? You could use either CSS or JavaScript to perform the edits, but ultimately you’ll likely need some JS code to create a toggle button. This alternative is perfect for keeping your home page dynamic and full of rich web media. Instead of completely removing your drop-down navigation or rearranging the page structure you can hide it within a content div. If the user wants to display your links they tap a toggle button to open/close the menu. This formatting is simple, intuitive, and easy to work with on touchscreen devices. Inside the div you can place each of the dropdown menus side-by-side in a column format. As the window resizes even smaller they will naturally drop below each other and increase the page height. Yet the option to collapse the entire menu is easily attainable and just a single tap away. This toggle div is also perfect for image sliders in cooperation with dynamic photo re-sizing. Using Media QueriesIf a mobile screen would break your 2 or 3-column layout you’ll end up with each of the content areas stacked above each other. The whole site would appear to bleed over and may come off very confusing without distinguished block areas. A better idea is to add a bottom border on each column, only for mobile devices, using an external stylesheet like mobile.css. <link rel="stylesheet" type="text/css" media="screen and (max-device-width: 480px)" href="css/mobile.css" /> With these new styles your content is broken up into divisible sections. The media attribute above is specially designed to target older iPhone devices in landscape view. But it will also apply to devices with screens smaller than 480 pixels. Use this to your advantage so you can determine at what point the layout “breaks up”. There are a few more options you can use for detecting device orientation. This fantastic guide on CSS media can give you a few ideas. Additionally the new mobile project 320 and up offers a boilerplate for mobile CSS @media styles. These can be included directly into the same mobile.css file and apply rules for many 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) { /* Styles */ } /* Smartphones (portrait) ----------- */ @media only screen and (max-width : 320px) { /* Styles */ } /* iPads (portrait and landscape) ----------- */ @media only screen and (min-device-width : 768px) and (max-device-width : 1024px) { /* Styles */ } (Source: Hardboiled CSS3 Media Queries) Helpful Tools
Showcase: Beautiful Responsive DesignsI hope these tips and design techniques will encourage you to move towards building exciting responsive layouts not just for mobile screens, but for any common device with web browsing. To keep the creative juices flowing I have put together a small showcase of responsive mobile web designs. Be sure to check out some of the more unique features and share your thoughts on the design or the topic in the discussion area. Dentistry’s Information Centre Stay tuned!In tomorrow’s post we’ll be showcasing some free responsive WordPress themes you can download for use. Be sure to tune in for that. Related posts: |
A Look Into: CSS3 :First-Of-Type Structural Selector Posted: 16 Jul 2012 06:33 AM PDT One thing that I love about CSS3 is is the new addition of selectors that allow us to target elements specifically without relying on the The h2:first-of-type { /* style declaration */ } The h2:nth-of-type(2) { /* style declaration */ } :first-of-type” vs. “:first-child”It may seem like these two selectors are doing the same thing, but that’s not the case. Let’s see the following demonstration: Let’s say we have five paragraph elements wrapped within a <div> <p>Pragraph 1</p> <p>Pragraph 2</p> <p>Pragraph 3</p> <p>Pragraph 4</p> <p>Pragraph 5</p> </div> Now, we would like to select the first paragraph using the p:first-child { padding: 5px 10px; border-radius: 2px; background: #8960a7; color: #fff; border: 1px solid #5b456a; } And as we’ve anticipated, the first paragraph is successfully selected. However, when we add a different element before the first paragraph, let’s say an <div> <h1>Heading 1</h1> <p>Pragraph 1</p> <p>Pragraph 2</p> <p>Pragraph 3</p> <p>Pragraph 4</p> <p>Pragraph 5</p> </div> the first paragraph will not be selected, as the first child inside the So, this is the situation where the p:first-of-type { padding: 5px 10px; border-radius: 2px; background: #a8b700; color: #fff; border: 1px solid #597500; } The “Last” SelectorWhere there is the “first”, then there will also be the “last”. The reverse of the two selectors we have discussed above are the following two selectors; the For example, this snippet below will target the last paragraph inside the div. p:last-child { padding: 5px 10px; border-radius: 2px; background: #8960a7; color: #fff; border: 1px solid #5b456a; } And this snippet will also target the last paragraph in the same situation as we have discussed above; this time the p:last-of-type { padding: 5px 10px; border-radius: 2px; background: #a8b700; color: #fff; border: 1px solid #597500; } The SelectivizrLike any other new feature in CSS3, these selectors are not supported in old browsers, mainly Internet Explorer 6 to 8, with an exception for the So, if all these selectors we’ve mentioned here are really required for your webite, you can use a JavaScript Library called Selectivizr to emulate those CSS3 selector’s functionality. The Selectivizr is dependent on other JavaScript Libraries in order to work, such as the jQuery, Dojo, Prototype and MooTools; and seeing from the comparison table in the official website, MooTools seems to be able to handle all the selectors. So, let’s include it along with the Selectivizr, as follows: <!--[if lte IE 8]> <script type="text/javascript" src="mootools,js"></script> <script type="text/javascript" src="selectivizr.js"></script> <![endif]--> The conditional comment above will ensure that these libraries will only be loaded in Internet Explorer 8 and below. Finally, you can view the demo from the following links and it should now work both in modern and old browsers (IE8 and below). You can also download the source file for further examination. Enjoy. Related posts: |
How To Assign Shortcuts to Any Program in Windows [Quicktip] Posted: 02 Jul 2012 03:10 AM PDT When you have many applications installed on your computer, it may take some time for you to locate and launch any particular application from the ‘Start’ menu, since you need to find the launch or shortcut button first. Even when you create shortcut buttons on your desktop, the problem remains the same if you have tons of applications to search through. Actually using keyboard shortcuts or ‘hotkeys’ could be the best solution. For example, using Ctrl + P to launch your Paint application would be a lot easier and faster than scanning your desktop for the Paint icon, won’t it? But can this be done on your Windows? Well, get this hotkey function activated on your computer with KeyboardExt, a desktop application that actually lists all your available applications in one simple window so you can quickly locate and launch your applications. KeyboardExt also provides the option to assign hotkeys to your applications, and we will show you how with this tutorial. Setting up KeyboardExtTo start off, go to the official page to download KeyboardExt and install. Once downloaded and installed, click open the KeyboardExt application, and you will see a window with a full list of applications that are available on your computer. This is the window that will help you to quickly locate and launch your applications, simply locate and click on the application to launch. Setting up HotkeysTo make it even faster, let’s set the ‘Hotkeys’. Click on the button ‘Hotkeys’ at the top right side of the window. In this page, you will see a preset keyboard shortcut to some of the applications that’s available on your computer. Click on ‘New Hotkey’ link just above the list, to start assigning a new hotkey. A small window will pop up with some options. To set new hotkeys, follow these simple instructions.
System HotkeysThere are preset hotkeys available for some of the regular actions one uses on desktop. To find out, click on the ‘Options’ tab and go to ‘System Hotkeys’. In the list of Hotkeys available, simply check the box to activate the hotkey, and uncheck to deactivate. ConclusionWith KeyboardExt, you can now search from Wikipedia by pressing Ctrl + W on your keyboard! Launching desktop applications now only require a keyboard shortcut. One setback from all of this could be that you will start to forget how your start menu look like soon. Related posts: |
You are subscribed to email updates from hongkiat.com To stop receiving these emails, you may unsubscribe now. | Email delivery powered by Google |
Google Inc., 20 West Kinzie, Chicago IL USA 60610 |
0 comments:
Post a Comment