G$earch

10 Useful Fallback Methods For CSS and Javascript

Posted by Harshad

10 Useful Fallback Methods For CSS and Javascript


10 Useful Fallback Methods For CSS and Javascript

Posted: 09 Jul 2012 03:27 AM PDT

Code fallbacks are the perfect solution for compromising with your many unique visitors. Not everybody on the web is using the same operating system, web browser, or even physical hardware. All of these factor into how your webpage will actually render on screen. When working with new CSS or JavaScript tricks you’ll often run into such technical bugs.

But don’t let these pitfalls discourage you! In this guide I’ve put together some of the most common fallback techniques for web designers focusing on CSS and JavaScript/jQuery. When all else fails you want to provide users at least basic page functionality. Simplicity reigns supreme in the field of user experience design.

Check out our guide below and let us know your thoughts and questions in the comments section.

1. Rounded Corners with Images

CSS3 techniques have skyrocketed into mainstream web design. One of the most notable properties is border-radius which allows for on-the-fly rounded corners. These look beautiful on practically any button, div, or text box. The only problem is the limited support between web browsers.

Many older browsers including Internet Explorer 7 do not support this property. So in order to keep rounded corners working for all standard browsers you’ll need to build a fallback with images. This tutorial provides a great example of how you can set up a unique .png image file with each of the four corners designed in Photoshop.

CSS3 rounded corner generator

The standard code uses regular CSS3 properties on the main div while accommodating for images on each of the corners. You’ll likely need to set up some extra divs within the main container which are used to display corner images in the background.

#mainbox {    -webkit-border-radius: 5px;  /* Safari */    -moz-border-radius: 5px;    /* Firefox\Gecko Engine */    -o-border-radius: 5px;     /* Opera */    border-radius: 5px;  }    #mainbox .topc {   	background: url('corner-tl.png') no-repeat top left;  }  #mainbox .topc span {   	background: url('corner-tr.png') no-repeat top right;  }  #mainbox .btmc {  	background: url('corner-bl.png') no-repeat bottom left;  }  #mainbox .btmc span {  	background: url('corner-br.png') no-repeat bottom right;  }  

To save yourself from stress I highly suggest using an app like RoundedCornr. It is an in-browser web app which generates rounded corner CSS using both CSS3 and images. This will be especially useful to designers who do not have access to graphics software such as Photoshop or GIMP.

2. jQuery Dropdown Menu System

Dropdown menu systems are perfect for today’s Web. However the biggest issue is visitors accessing your website without the JavaScript enabled. In this case none of your menus would work at all! The best solution is using CSS to display/hide each of the sub-menu div blocks and display them on hover.

CSS-Plus jQuery Menu

The only problem with this solution is that Internet Explorer 6 doesn’t support these CSS hover selectors. However IE7+ works great; and of course all browsers will work fine if JavaScript is enabled in the first place. The code from this tutorial on CSS Plus is one of the best resources I’ve found. It provides not only a solution with jQuery but also the CSS necessary for IE issues.

/* A class of current will be added via jQuery */  #nav li.current > a {  	background: #f7f7f7;  }  /* CSS fallback */  #nav li:hover > ul.child {  	display: block;  }  #nav li:hover > ul.grandchild {  	display: block;  }  

Source

Another alternative solution you can try is just openly displaying each of the menus in IE6. You can use Internet Explorer conditional comments to apply stylesheets based on the browser version. Of course, this won’t be the prettiest solution, but it will simply work.

If you don’t feel that Internet Explorer 6 is much of a worry then don’t even bother with this alternative fallback. The tutorial and subsequent code above should be enough to get your JavaScript menu loading even with strict CSS in all of the major browsers.

3. Targeted Internet Explorer Styles

I’m sure we all know about the rendering issues coming out of Microsoft’s Internet Explorer. I can give a bit of credit for their latest IE8 and future prospects with IE9. However there is still a small audience running IE6/IE7 and you really can’t ignore them just yet.


(Image source: github)

Conditional comments as mentioned in the last section can be useful for reformatting areas of the page. For example if you have a dropdown menu with sub-navigation in IE6 that will only display using JavaScript, you’ll be out of luck trying CSS as a fallback method. Instead the best solution is to display each sub-list as a navigation block.

<!--[if IE 6]>  <link rel="stylesheet" type="text/css" media="all" href="css/ie6.css" />  <![endif]-->  

Adding the above code to your document header you can then specify the display type for each sub-navigation. The best part about this fallback is that you can overwrite the CSS and still dynamically show/hide menus when JavaScript is enabled. Otherwise you’ll just display an open list of links. You could use a similar code like what I’ve added below.

#nav li {    position: relative;    width: 150px; /* must set a finite width for IE */  }  #nav li ul { /* sub-nav codes */    display: block;    position: absolute;    width: auto; /* define your own width or set in the li element */  }  #nav li ul li {    width: 100%;  }  

4. Legacy IE Opacity/Transparency

One of the many annoying bugs with Internet Explorer is the deal with opacity. The alpha-transparency settings in CSS3 can be altered through the opacity property. Yet in the way of Microsoft only Internet Explorer 9 currently supports this feature.

The best solution for targeting IE6+ is through filter, a proprietary setting only recognized by IE. Check out the brief code example below:

.mydiv {    opacity: 0.55; /* CSS3 */    filter: alpha(opacity=55); /* IE6+ */  }  

All you need to do is include the line above within any element requiring transparency. Notice that similar to the CSS3 property, all child elements will also inherit this opacity change. If you are looking for a newer method which targets IE8 specifically, check out the code below. It behaves in the same manner as our filter property is only recognized by the Microsoft IE8 parser.

-ms-filter: "progid:DXImageTransform.Microsoft.Alpha(opacity=55)"; /* IE8 */  

5. Creating CSS3 Buttons with Fallback Images

Buttons are a fantastic web element for all kinds of interfaces. They can behave as form inputs, navigation items, or even direct page links. With CSS3 it’s now possible to format buttons with many unique styles such as background gradients, box shadows, rounded corners, etc.

However you cannot trust that all your visitors will be able to render these newer properties. When building a fallback design for buttons (or even similar UI elements) there are two distinct options. The first is to include a background image designed exactly as the CSS would look. This can be easily accomplished in Photoshop. However if you’re not an expert in the software then this may be troublesome.

CSS3 rounded buttons tutorial from Web Designer Wall

The alternative is to fallback to a plain background color and simpler CSS styles. I’m using some of the code examples from CSS-Tricks great post on CSS3 gradients. All the major browsers including Safari, Firefox, Chrome, and even Opera support these properties. The area where you’ll run into issues is in the support of legacy browsers: older Mozilla engines, IE6/7, possibly even Mobile Safari.

.gradient-bg {    background-color: #1a82f7; /* uses a solid color at worst */    background-image: url('http://media02.hongkiat.com/code-fallback-methods/fallback-gradient.png');    background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#2F2727), to(#1a82f7));    background-image: -webkit-linear-gradient(top, #2F2727, #1a82f7);    background-image: -moz-linear-gradient(top, #2F2727, #1a82f7);    background-image: -ms-linear-gradient(top, #2F2727, #1a82f7);    background-image: -o-linear-gradient(top, #2F2727, #1a82f7);  }  

Source

The only small issue with solely using images as a fallback method is that you won’t have an active state change when the user clicks on a button. You could build two different images for these regular vs. active states, although it would take some extra work. This reason alone may push you to use a solid background color instead of fallback images. Try out a couple of different solutions to see which looks best in your layout.

6. Checking for Mobile Content

Another huge trend in 2012 is the popularity of mobile Internet browsing. Smartphones are everywhere and data over 3G/Wi-Fi is becoming more and more accessible. Thus many designers will be looking to provide a fallback layout for mobile users.

A couple of popular mobile web browsers will render pages similar to a desktop environment. Mobile Safari and Opera are best known for this, even supporting many common jQuery scripts. But these pages are not always mobile-friendly and there is room to expand on UX.

Apple iPhone 4S model - Black

There are two ways you can detect mobile browsers and display an alternate layout or stylesheet. The first is through JavaScript which works great as a frontend tool. The script I’ve added below is very simple and only checks for iPhone/iPod Touch users. Detect Mobile Browsers is a fantastic website which offers a more detailed script you can run instead.

// Redirect iPhone/iPod Touch  function isiPhone(){    return (      (navigator.platform.indexOf("iPhone") != -1) ||      (navigator.platform.indexOf("iPod") != -1)    );  }  if(isiPhone()){    window.location = "m.yourdomain.com";  }  

Now the other alternative is checking through a backend language such as PHP. You can check for a variable known as the HTTP_USER_AGENT. Dozens of websites will turn up if you google these terms. However I still recommend the Detect Mobile Browsers link I added in the previous paragraph.

The site has free downloadable scripts for parsing not only in PHP, but also tons of other popular backend languages. These include ASP.NET, ColdFusion, Rails, Perl, Python, and even server-based code such as IIS and Apache.

7. Slicebox Slider with Graceful Fallback

My favorite CSS3 freebie from 2011 probably has to be the Slicebox 3D Image Slider released by Codrops. It utilizes beautiful CSS animation transitions in browsers which support them, currently in Google Chrome and the latest in Safari. It’s weird that even the most recent Firefox or IE9 release still can’t use these transitions.

Codrops animated transitions image gallery

The best part about this code is that it’ll still fallback to provide basic transition effects between the images. Granted much of the animation is performed through jQuery, but the standard CSS fallback option is still very reliable considering how many browsers cannot support flashy CSS3 animations.

Alternatively Codrops also just recently released another sliding images panel which utilizes even more creative CSS3 techniques. This image slider is created using background images in CSS, so even without the transition effects it behaves very smoothly.

8. jQuery Script CDN Failsafe Method

The jQuery library has become almost essential for developing JavaScript on the web. Many alternate CDN suppliers have created static URLs where they host all the release versions of jQuery. Google, Microsoft, and even jQuery themselves have created a CDN portal for developers, among a few other lesser-known websites.

There are possibly hundreds of thousands of developers reliant on these providers. What would happen if any of the links were broken for whatever reason or the servers went offline? It would be a good idea to host a local copy and implement this only if you would need it. Well this great fallback code snippet from CSS-Tricks lets you do just that!

<script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery/jquery-1.7.1.min.js"></script>  <script type="text/javascript">  if (typeof jQuery == 'undefined') {    document.write(unescape("%3Cscript src='/js/jquery-1.7.1.min.js' type='text/javascript'%3E%3C/script%3E"));  }  </script>  

Source

9. Unique HTML5 Checkboxes

HTML5 has opened the door for some fresh cool styles to build websites. Part of this enhanced web experience is through forms and input elements. Checkboxes are just one example which can be heavily customized to fit your needs.

I ran into this wonderful CSS/jQuery tutorial posted back in early Spring 2011. It offers a simple method of creating Apple-style switches for your checkboxes which gracefully degrade in older browsers. The code uses background images to replace the on/off styles between user interactions.

TutorialZine design - iOS styled iPhone Checkboxes with graceful fallback

The original input checkbox elements are hidden by default and their value is determined through JavaScript calls. This means you can dynamically pull the value at any point through jQuery, but it will also be passed into the form upon hitting the “submit” button.

Assuming that JavaScript is turned off or unsupported in older browsers the script will default to regular HTML inputs. This will also disable the CSS for the newer checkbox styles so it’ll appear as if nothing has changed. The script behaves more like an aesthetic front-runner with a clean fallback than anything else. But these sliders look fantastic, and the same techniques could be applied to other form input fields such as select menus and radio buttons.

10. HTML5 Supported Video

The new HTML5 specs have been very progressive in many areas. Both video and audio elements have enhanced native support for a large number of media files. However it does turn out that between the HTML5-supported browsers they do not all agree on file types.

Mozilla Firefox generally supports .OGG video which you can use VLC as a converter. Google Chrome & Safari look for .MP4 or H.264 encoded .MOV files. Because of these differences you would normally have to include three different video formats – the two listed above along with an .FLV fallback.

Basic HTML5 and Flash video player VideoJS

Thankfully some really smart guys put together a library called VideoJS. It’s an extremely small JavaScript build which allows for a single implementation of Flash and HTML5 video in one tag. It’s free to download and open source, so developers are welcome to contribute as well. Both the Flash and HTML5 video players are customized to be identical so all users will have the same experience. Check out their HTML5 video embed code example:

  <video id="mainVid" class="video-js vjs-default-skin" controls      preload="auto" width="640" height="480" poster="http://media02.hongkiat.com/code-fallback-methods/default_preview_img.png"      data-setup="{}">      <source src="my_video.mp4" type="video/mp4">      <source src="my_video.webm" type="video/webm">  </video>  

Source

Following a similar route the html5media project offers a method for consolidating all streaming media into one filetype. Unfortunately even VideoJS isn’t perfect with every single browser. What the html5media project has tried to do is work around browser incompatibilities to support any video file type amongst all platforms. And it actually works quite well!

Conclusion

I hope this guide of useful fallback methods will come in handy for web developers around the world. It can be tough building websites to adapt to a wide range of software specifications. This is especially true when you’re working with many different languages such as CSS and JavaScript.

But trends are indicating that we’re approaching a more supportive era in web design. Never before have more browsers and web standards been agreed upon, especially within CSS3 & HTML5. These techniques are just some of the many to consider when building standards-compliant web pages. As a web developer, you’ll constantly want to be following the latest design trends and adapting to best suit your audience.

Related posts:

  1. Beginner’s Guide to Node.js (Server-side JavaScript)
  2. HTML5 Tutorial: How to Build a Single Product Page

15 Android Apps Every Blogger Should Have

Posted: 09 Jul 2012 03:09 AM PDT

Blogging has always been about expressing yourself and sharing what you know on the Internet. Android as an operating system is growing fast thanks to its availability on a wide range of smartphones and tablet devices as well as the fast growing number of applications that are available in Google Play. With huge amounts of innovation spurring the technological advancement of mobile phones and the landscape of mobile apps, bloggers these days are offered the opportunity to not only blog on-the-go, but also to conduct many blogging-related tasks on their smartphones when they are away from their computer.

The following are 15 free Android apps that you should check out and download if you are an avid blogger who update multiple blogs regularly. They cost nothing so feel free to try them out on your phone.

1. WordPress

WordPress is undoubtedly the most popular blogging platform on the Internet. This app, made compatible with self-hosted WordPress blogs as well as blogs hosted on WordPress.com, allows you to perform many essential tasks such as creating, editing and publishing blog posts, moderating comments, checking on analytics data as well as publishing photos or videos taken with the camera on your mobile phone.

2. Blogger

Blogger is another popular platform that many personal bloggers use. If you have a blog on Blogger, then you should definitely give this app a try. However, the functionality of this app is still very limited as compared to the WordPress app, which is surprising as Google itself is behind this official app of their blogging service.

3. Tumblr

Many bloggers prefer to maintain a Tumblr blog, also known as a microblog, rather than a full blown blog. This is because posting short blurbs of interesting content such as quotes, videos and photos are less taxing. This app, made for Tumblr bloggers, has useful features for posting content, scheduling posts, viewing and replying to messages, and you can even manage multiple Tumblr blogs with the app. It will also show you Tumblr blogs of Contacts in your address book, so you can start following them.

4. Writer

Blogging and getting things done using your smartphone is not easy, especially when there are so many distractions on the screen itself. Apps and incoming notifications are the most common productivity killers. Writer is a stripped-down word processor that aims to solve this problem by providing a distraction-free writing environment within your smartphone or tablet so that you can focus solely on creating text content with peace of mind.

5. Google Drive

Google Drive allows bloggers to store all kinds of documents including Word documents, Excel spreadsheets, images, audio, videos and many others in the Cloud. Apart from just storing them, the app will sync these documents across multiple devices linked to your Google account. Once synchronized, bloggers can access their files wherever they are. If you have a blog post that is halfway done on your laptop, you can continue to work on it using your phone while commuting to work.

6. Dictionary.com

Not sure about the exact meaning of a word that you are going to put into your blog post? Eager to find an alternative word to use in your post? Want to know the meaning of a word or phrase used in comments posted by your readers? Well, Dictionary.com is the solution for all the above problems. The app is especially useful for bloggers that don’t speak English natively and the ad-free version only costs $2.99.

7. SwiftKey Keyboard

This is a dream-come-true app for those who are tired of typos and the small keyboard buttons on your tablets or smartphones. SwiftKey Keyboard does not only auto-correct your typos, it also offers word predictions based on your past typing activities. You can even personalize the word predictions by asking the keyboard to learn your choice of words on Facebook, Twitter, Gmail and blog posts.

8. Photo Editor

With a smartphone, we can snap photos on-the-go and attach them to our blog posts either immediately or in the near future. From time to time, we might need to do some minor touch-ups on the photos that we’ve taken and this is where Photo Editor comes in. With this app, you can crop, edit, and resize your photos as well as add effects, texts and drawings onto them.

9. Disqus

Many bloggers are integrating the Disqus commenting system onto their blogs because of the community features that bring blog commenters back and keep them engaged. With the Disqus Android app, you can moderate your comments, publish responses to comments that you receive and keep the engagement levels high despite being away from your computer.

10. Flipboard

Flipboard only launched its Android app recently. The app allows users to browse through their Facebook, Twitter and Google+ streams, as well as Google Reader feeds in a beautiful flipping manner. It also consolidates and curates a stream of important stories for those who are too busy to go through everything. As a blogger, using this app and browsing through interesting news content daily will give you fresh ideas on what to write about in your next blog post.

11. BeyondPod Podcast Manager

Bloggers who don’t have time or don’t like to read may prefer to listen to audio content or watch videos. BeyondPod allows you to subscribe, download, listen to audio podcasts and watch video podcasts on-the-go. This app is extremely useful for bloggers who are driving a lot because for them, there is very little reading time.

12. Pocket

As bloggers, we tend to browse the Internet a lot on smartphones, and will come across insightful articles and blog posts that we would love to read but cannot due to limited time. Pocket solves this problem by letting us save links that we wish to read later. The app will download a minimalist version of an article, blog post, video or just about everything so that we can come back to them later.

13. Evernote

Evernote is a very useful app to capture ideas that come to mind when you are out and about. You can capture an image, write text, do sketches (with Skitch), record an audio clip or create a to-do list with Evernote. All these materials will then synchronized across all your devices so you can be sure that all your notes are easily accessed via your phone, desktop and browser.

14. Tape-a-Talk Voice Recorder

An app that records audio is very important for bloggers. You can use this app to record an interview with an authority figure in your industry, or make note-to-self reminders. Apart from recording, Tape-a-Talk has the functionality of uploading your recording to several services once the recording is completed. The paid version, which costs $4.99, comes with basic editing features such as cut, repair and rename.

15. gAnalytics

The amount of traffic that you receive together with other site metrics like bounce rates are crucial if you are making any form of income from your blog. gAnalytics is like the mobile version of Google Analytics which basically allows you to bring site usage statistics wherever you go. With this app, you can stop worrying about the traffic performance of your blog the next time you travel.

Did I Miss Out Any Useful Apps?

Fellow bloggers, were there any apps other than the ones mentioned above that you use on a daily basis? Do you have experience using the above apps or with any other apps outside of this list that you’d like to share with us? Leave your two cents in the comments below.

Editor’s note: This article is contributed by Wayne Liew, a blogger, entrepreneur and tech geek who blogs about small business and entrepreneurship over at Sprout Geek. Currently, Wayne is also helping Lazada Malaysia, the largest online shopping mall in Malaysia, with their online marketing initiatives.

Related posts:

  1. Top 20 Android Photography Apps
  2. 65 Useful Android Apps for Designers
  3. Siri Alternative Apps for Android – Best Of
  4. How To Sync ITunes From Mac to Android [Quicktip]

How to Include Mouse Pointer in a Screen Capture [Quicktip]

Posted: 02 Jul 2012 03:07 AM PDT

[Mac only] Have you ever wanted to have your mouse cursor captured in your screenshot but could never make it happen? If you haven’t noticed, whether on a Mac or PC, every time you capture a screenshot, your mouse cursor cannot be found. Give it a shot.

Grab for Mac

If it is necessary to have the cursor in the screenshot, some of us may choose to edit the cursor in, which is a tad bit of a hassle. Why not just have the cursor snapped in together in the screenshot?

In this tutorial, we will show you how you can utilize a Mac tool to add in your mouse cursor, without installing any application or editing your photo. This tool is called ‘Grab’, and it’s a screenshot utility already available in your Mac.

1. ‘Grab’ Preferences

To start using Grab, go to your Applications > Utilities folder, look for ‘Grab’ and launch it. Click on ‘Preferences’ to select your mouse pointer.

Grab preferences

2. select Mouse pointer

When you click on ‘Preferences’, a new window will pop up with a selection of pointer types you can use for screenshot purposes. Select the type of your choice.

Grab Mouse Type

Check the ‘Enable Sound’ to hear the screenshot capture sound effect.

3. Capture Style

Now that the mouse pointer is selected, go to the ‘Capture’ tab and click on either ‘Screen’ or ‘Timed Screen’ since these two options work best to capture the mouse cursor in your screenshot.

Grap Capture

  1. When ‘Screen’ is selected, a new window will appear to guide you on your screen grab. To start capture, click anywhere on your window area.

  2. This guide window will not appear in your screenshot, and your mouse pointer will appear as selected earlier.

    Grab Screen

  3. When ‘Timed Screen’ is selected, another guide window will appear and you will have 10 seconds to prepare where you want to place your mouse pointer.

    Click on the ‘Start Timer’ and position your cursor where you want it within 10 seconds.

    Grab Timed Screen

4. The screenshot

After a screenshot is captured by Grab, a new window will appear with a snapshot showing your result.

Grab Screenshot Result

To save the image, click on ‘File’ and ‘Save’. Note that file will be saved in ‘.TIFF’ format,

Grab Save

Alternatively, if you want to copy the image and save it elsewhere, click on ‘Edit’ and then ‘Copy’ and just paste it elsewhere.

Grab copy

Conclusion

Capturing a screenshot has never been this easier. No more hide-and-seek with the elusive mouse cursor. Without even installing any application, you can get your cursor in a good screenshot.

Related posts:

  1. How To Turn Your IPhone into a Temporary Keyboard And Mouse
  2. How to Transfer iOS Screenshots To Your Mac Easily [Quicktip]
  3. How To Turn Android Device into Keyboard And Mouse
  4. How to Browse Instagram Like Pinterest [Quicktip]

0 comments:

Post a Comment