CSS-Tricks

New Screencast: Basics & Tips on Designing for the iPhone

*   October 2nd, 2008   *

by: Chris Coyier

Designing a web page that is optimized for the iPhone isn’t rocket science. It’s the same HTML, CSS and JavaScript that you already know. The difference is that browsers and screens do not vary, you know exactly what you are dealing with. You can use that to your advantage and think about that experience when you create your UI. I start out with how to get your page formatted correctly, how to have differnet stylesheets for portrait and horizontal mode, how to create a “Back to Top” button, and then show some iPhone pages I’ve made.

View Demo Download Files

Code Snippets from the Video and Download


<script type="application/x-javascript">
	addEventListener('load', function() {
		setTimeout(hideAddressBar, 0);
	}, false);
	function hideAddressBar() {
		window.scrollTo(0, 1);
	}
</script>

<script type="text/javascript">
	function orient()
	{
		switch(window.orientation){
			case 0: document.getElementById("orient_css").href = "stylesheets/iphone_portrait.css";
			break;

			case -90: document.getElementById("orient_css").href = "stylesheets/iphone_landscape.css";
			break;

			case 90: document.getElementById("orient_css").href = "stylesheets/iphone_landscape.css";
			break;
		}
	}
	window.onload = orient();
</script>

The above requires and ID attribute of “orient_css” on the link to the stylesheet.


<script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
<script type="text/javascript">
	$(function(){
		$('.backtotop').click(function() {
			$('html, body').animate({scrollTop:0}, 'slow');
			return false;
		});
	});
</script>

Bookmark at Delicious Digg this! Stumble this! Submit to DesignFloat Submit to DZone

Responses


  1. Gravatar

    Marco
    October 2, 2008
    [ permalink ]

    Thanks for the info Chris!

    Just wondering why you didn’t add “180″ (when the phone is turned upside down) to the orientation?

  2. Gravatar

    Curvball
    October 2, 2008
    [ permalink ]

    This is perfect - been meaning to get into designing something for the iPhone and this is very handy - bookmarked. Thanks.

  3. Gravatar

    Chris Coyier
    October 2, 2008
    [ permalink ]

    @Marco: The iPhone don’t do upside down =). In fact if you turn it upside down it just retains whatever orientation it already had, no change is registered. (at least in Safari).

  4. Gravatar

    Brian
    October 2, 2008
    [ permalink ]

    Chris thanks for the article and video. I can’t wait till 100% of the web is viewable on portable devices. This could potentially make ‘web browsing, designing and developing’ much more to the point!

    Enough with adverts and popups! The screen will only be large enough to display so much…

  5. Gravatar

    Phil Havens
    October 2, 2008
    [ permalink ]

    Did the podcast URL get mixed up? Says the podcast URL is invalid in iTunes.

  6. Gravatar

    Chris Coyier
    October 2, 2008
    [ permalink ]

    @Phil - I think I got it fixed. I had an un-escaped ampersand in the title that was killing the feed.

  7. Gravatar

    Tommy Day
    October 2, 2008
    [ permalink ]

    My favorite screencast so far, keep it up!

  8. Gravatar

    intermission*
    October 2, 2008
    [ permalink ]

    Yeah, really cool stuff. Learning it takes a bit of time but once you know it it’s a cinch.

    Check out our iphone site: iphone.intermissiondesign.com

  9. Gravatar

    Ariyo
    October 4, 2008
    [ permalink ]

    Hey chris thanks for these awesome screen casts. Good stuff indeed. One thing I noticed in the video page is that the link for status page is not working. I think you missed the HQ from the link. it supposed to be statushq.com
    Cheers!

  10. Gravatar

    Chris Coyier
    October 4, 2008
    [ permalink ]

    @Ariyo: Thanks! Got that link fixed.


Leave a Comment

Gravatar

Your Name
December 3, 2008