Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Save more on your purchases! discount-offer-chevron-icon
Savings automatically calculated. No voucher code required.
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletter Hub
Free Learning
Arrow right icon
timer SALE ENDS IN
0 Days
:
00 Hours
:
00 Minutes
:
00 Seconds
HTML5 Web Application Development By Example : Beginner's guide
HTML5 Web Application Development By Example : Beginner's guide

HTML5 Web Application Development By Example : Beginner's guide: Learn how to write rich, interactive web applications using HTML5 and CSS3 through real-world examples. In a world of proliferating platforms and devices, being able to create your own “go-anywhere” applications gives you a significant advantage.

eBook
$25.99 $28.99
Paperback
$48.99
Subscription
Free Trial
Renews at $19.99p/m

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Table of content icon View table of contents Preview book icon Preview Book

HTML5 Web Application Development By Example : Beginner's guide

Chapter 2. Let's Get Stylish

"In matters of style, swim with the current; in matters of principle, stand like a rock." – Thomas Jefferson

In this chapter, we will put on our graphic designer hats and do some styling. Right now our task list application that we created in the first chapter works but it looks like something from 2005. We will bring it up to the present and into the future using CSS3 to give it a clean, modern look. We will add rounded corners, shadows, gradients, and transitions using the latest CSS3 features. We will also use CSS sprites to add some images to the task list buttons.

In this chapter we will learn:

  • New ways to specify colors in CSS3 and set transparencies
  • How to add rounded corners to elements
  • How to add shadows to elements and text
  • How to draw gradients in element backgrounds
  • New CSS3 background properties
  • How to use CSS sprites in your applications
  • How to use transitions and transforms to add effects to the user interface
  • How to dynamically...

CSS3 overview

CSS3 is not part of the HTML5 specification, but it is an integral part of writing HTML5 applications. CSS3 is being developed in tandem with HTML5 and provides many new styles to make web pages look and function better than ever. Things that were once the realm of Photoshop, such as gradients and shadows, are now easily added via styling. Using these new graphics features will make your applications look modern and add character to your applications.

Some of the most exciting additions to CSS are the ability to add gradients and shadows to elements. Rounded corners, a feature that everyone wanted in their web pages, and which were once the realm of many HTML hacks, are now simple to add. It has never been easier to make web pages and applications look good without having to download extra images and code to support them.

You can see examples of all the following CSS3 styles in chapter2/css3-examples/css3-examples.html.

CSS3 colors

Before we get started with the new effects,...

Rounded corners

The first CSS3 effect that we'll look at is rounded corners, since that was such a sought-after feature before CSS3. In the past, if you wanted rounded corners, there were only a few non-optimal solutions available. You could load four images, one for each corner, and add some extra markup to get them to line up (and try to make it work in all browsers). Or implement some kind of hack using multiple div tags to "draw" a rounded border. Or one of a half a dozen other ways. In the end none of them were great solutions. So why did we go to such lengths to make rounded corners work before CSS3? Because people are attracted to them and they just seem to make your design look more natural.

Rounded corners are ridiculously easy to add to elements using CSS3's new border-radius property. If you want each corner to have the same border radius, just give it one value, like this:

border-radius: 0.5em;

If you want to set each corner of the border to a different radius...

Shadows

Adding shadows to elements and text is simple in CSS3. Use shadows to make certain elements really stand out and give a more natural look to your UI. There are many options for adding shadows, such as size, position, and color. Shadows don't always have to be behind elements and text; they can frame, highlight, and add effects to them too.

Box shadows

In addition to rounded corners, you can add shadows to elements using the new CSS3 box-shadow property. The box-shadow property takes a number of parameters that tells it how to draw the shadow:

box-shadow: h-offset v-offset blur-radius spread-radius color;

Here is an explanation of the parameters:

  • h-offset: The horizontal offset of the shadow. Negative values put the shadow to the left of the element.
  • v-offset: The vertical offset of the shadow. Negative values put the shadow above the element.
  • blur-radius: Determines the blur amount; the higher the number, the more blur (optional).
  • spread-radius: The size of the shadow. If zero, it...

Time for action – styles in action

Let's put the border-radius and box-shadow effects to good use in our task list application. First, we will center the task list on the page. Then we'll put a box around each task with rounded corners and a shadow. Let's open taskAtHand.css and make some changes. You can find the code for this section in chapter2/example2.1.

First, we'll change the style for the <div id="main"> element which contains the task-name text field and task list. Let's give this section a minimum width of 9em and a maximum width of 25em. We don't want the task list to get too wide or too small to make it easier to read. This will give us the beginnings of a reactive layout. We will also set the top and bottom margins to 1em, and the left and right margins to auto to center it on the page.

Note

A reactive layout is one that reacts to its environment by adjusting its layout to fit the device it is displayed on. By using reactive...

Backgrounds

There are a number of new styles for setting the background styles of elements. You can now easily draw gradients without using images. You can change the size and origin of background images, and even use multiple images in backgrounds.

Gradients draw a background for an element that fades from one color to one or more other colors. They give depth to your pages and add a more natural look. You can specify two different types of gradients in CSS3: linear and radial. Linear gradients are, well, linear. They flow from one color to another in a straight line. Radial gradients spread out from a central point in a radial fashion.

Linear gradients

Linear gradients are defined using the linear-gradient specifier on a background property. For the simplest form, you specify a start and end color using any of the color specifiers we discussed earlier in the section on colors, and it will draw the gradient from the top to the bottom of the element. The following fades from red to blue:

background...

Time for action – adding a gradient and button images

Let's use what we learned about gradients and background images to make our application look more interesting. First, we'll add a gradient to the background of our task list application. We will add a linear gradient to the <div id="app"> element. It will start with our previous background color at the top and fade into a dark blue color at the bottom. Notice how we keep the old background color as a fallback for browsers that don't support gradients:

#app
{
    margin: 4px;
    background-color: #bbc;
    background: -webkit-linear-gradient(top, #bbc, #558);
    background: -moz-linear-gradient(top, #bbc, #558);
    background: -ms-linear-gradient(top, #bbc, #558);
    background: linear-gradient(top, #bbc, #558);
}

This is how it would look:

Time for action – adding a gradient and button images

Now let's use CSS sprites to add images to the buttons in our task list application. We need images for delete, move up, and move down. Our buttons will...

CSS3 overview


CSS3 is not part of the HTML5 specification, but it is an integral part of writing HTML5 applications. CSS3 is being developed in tandem with HTML5 and provides many new styles to make web pages look and function better than ever. Things that were once the realm of Photoshop, such as gradients and shadows, are now easily added via styling. Using these new graphics features will make your applications look modern and add character to your applications.

Some of the most exciting additions to CSS are the ability to add gradients and shadows to elements. Rounded corners, a feature that everyone wanted in their web pages, and which were once the realm of many HTML hacks, are now simple to add. It has never been easier to make web pages and applications look good without having to download extra images and code to support them.

You can see examples of all the following CSS3 styles in chapter2/css3-examples/css3-examples.html.

CSS3 colors

Before we get started with the new effects, let...

Rounded corners


The first CSS3 effect that we'll look at is rounded corners, since that was such a sought-after feature before CSS3. In the past, if you wanted rounded corners, there were only a few non-optimal solutions available. You could load four images, one for each corner, and add some extra markup to get them to line up (and try to make it work in all browsers). Or implement some kind of hack using multiple div tags to "draw" a rounded border. Or one of a half a dozen other ways. In the end none of them were great solutions. So why did we go to such lengths to make rounded corners work before CSS3? Because people are attracted to them and they just seem to make your design look more natural.

Rounded corners are ridiculously easy to add to elements using CSS3's new border-radius property. If you want each corner to have the same border radius, just give it one value, like this:

border-radius: 0.5em;

If you want to set each corner of the border to a different radius, you can do that too...

Shadows


Adding shadows to elements and text is simple in CSS3. Use shadows to make certain elements really stand out and give a more natural look to your UI. There are many options for adding shadows, such as size, position, and color. Shadows don't always have to be behind elements and text; they can frame, highlight, and add effects to them too.

Box shadows

In addition to rounded corners, you can add shadows to elements using the new CSS3 box-shadow property. The box-shadow property takes a number of parameters that tells it how to draw the shadow:

box-shadow: h-offset v-offset blur-radius spread-radius color;

Here is an explanation of the parameters:

  • h-offset: The horizontal offset of the shadow. Negative values put the shadow to the left of the element.

  • v-offset: The vertical offset of the shadow. Negative values put the shadow above the element.

  • blur-radius: Determines the blur amount; the higher the number, the more blur (optional).

  • spread-radius: The size of the shadow. If zero, it's...

Time for action – styles in action


Let's put the border-radius and box-shadow effects to good use in our task list application. First, we will center the task list on the page. Then we'll put a box around each task with rounded corners and a shadow. Let's open taskAtHand.css and make some changes. You can find the code for this section in chapter2/example2.1.

First, we'll change the style for the <div id="main"> element which contains the task-name text field and task list. Let's give this section a minimum width of 9em and a maximum width of 25em. We don't want the task list to get too wide or too small to make it easier to read. This will give us the beginnings of a reactive layout. We will also set the top and bottom margins to 1em, and the left and right margins to auto to center it on the page.

Note

A reactive layout is one that reacts to its environment by adjusting its layout to fit the device it is displayed on. By using reactive layouts, you can ensure that your application works...

Backgrounds


There are a number of new styles for setting the background styles of elements. You can now easily draw gradients without using images. You can change the size and origin of background images, and even use multiple images in backgrounds.

Gradients draw a background for an element that fades from one color to one or more other colors. They give depth to your pages and add a more natural look. You can specify two different types of gradients in CSS3: linear and radial. Linear gradients are, well, linear. They flow from one color to another in a straight line. Radial gradients spread out from a central point in a radial fashion.

Linear gradients

Linear gradients are defined using the linear-gradient specifier on a background property. For the simplest form, you specify a start and end color using any of the color specifiers we discussed earlier in the section on colors, and it will draw the gradient from the top to the bottom of the element. The following fades from red to blue:

background...

Time for action – adding a gradient and button images


Let's use what we learned about gradients and background images to make our application look more interesting. First, we'll add a gradient to the background of our task list application. We will add a linear gradient to the <div id="app"> element. It will start with our previous background color at the top and fade into a dark blue color at the bottom. Notice how we keep the old background color as a fallback for browsers that don't support gradients:

#app
{
    margin: 4px;
    background-color: #bbc;
    background: -webkit-linear-gradient(top, #bbc, #558);
    background: -moz-linear-gradient(top, #bbc, #558);
    background: -ms-linear-gradient(top, #bbc, #558);
    background: linear-gradient(top, #bbc, #558);
}

This is how it would look:

Now let's use CSS sprites to add images to the buttons in our task list application. We need images for delete, move up, and move down. Our buttons will be 16x16 pixels, so our images will need...

Transitions


We have a pretty good looking UI now, but we can make it even better with some transitions. CSS3 transitions add animation effects to elements when their styles change. For example, if we change the size of an element, it will gradually change from smaller size to a larger size thereby providing visual feedback to the user. When things change gradually, it catches our eye more than something that just appears suddenly on the page.

The CSS3 transition property allows us to specify transitions on elements. It has the following format:

transition: property duration timing-function delay

Here is an explanation of the parameters:

  • property: The CSS property to add a transition to. For example, width or color. Use all to apply transitions to all the properties.

  • duration: The length of time the transition takes. For example, 0.5s takes half a second to complete the transition.

  • timing-function: Determines how the transition progresses over the duration:

    • linear: The same speed from beginning...

Transforms


CSS3 transforms provide even more sophisticated effects. There are 2D and 3D transformations available. We will discuss some of the 2D transformations here. Transforms can be used with transitions to provide some interesting effects. Here is the basic form of the transform property:

transform: function();

There are a few different 2D transform functions. The first we'll look at is translate(). It moves an element from its current position to a new position. It takes x and y positions as parameters. You can use negative values to move up and to the left. The following would move an element 10 pixels right and 25 pixels up:

transform: translate(10px, -25px);

The rotate() function rotates an element by a given amount. The rotation amount can be specified in degrees or radians. Use negative values to rotate counter clockwise, positive for clockwise:

transform: rotate(45deg);

The scale() function adjusts the size of an element by some factor. It takes one or two parameters. If only one...

Left arrow icon Right arrow icon

Key benefits

  • Packed with example applications that show you how to create rich, interactive applications and games.
  • Shows you how to use the most popular and widely supported features of HTML5.
  • Full of tips and tricks for writing more efficient and robust code while avoiding some of the pitfalls inherent to JavaScript.
  • Learn how to create professional looking applications using new CSS3 styles and responsive design.
  • Learn how to compress, package, and distribute your web applications on the Internet for fun or for profit.

Description

HTML5's new features have made it a real application development platform with widespread adoption throughout the industry for this purpose. Being able to create one application that can run on virtually any device from phone to desktop has made it the first choice among developers. Although JavaScript has been around for a while now, it wasn't until the introduction of HTML5 that we have been able to create dynamic, feature-rich applications rivaling those written for the desktop. HTML5 Web Application Development By Example will give you the knowledge you need to build rich, interactive web applications from the ground up, incorporating the most popular HTML5 and CSS3 features available right now. This book is full of tips, tools, and example applications that will get you started writing your own applications today. HTML5 Web Application Development By Example shows you how to write web applications using the most popular HTML5 and CSS3 features. This book is a practical, hands-on guide with numerous real-world and relevant examples. You will learn how to use local storage to save an application's state and incorporate CSS3 to make it look great. You will also learn how to use custom data attributes to implement data binding. We'll use the new Canvas API to create a drawing application, then use the Audio API to create a virtual piano, before turning it all into a game. The time to start using HTML5 is now. And HTML5 Web Application Development by Example will give you the tips and know-how to get started.

Who is this book for?

If you have no experience but want to learn how to create applications in HTML5, this book is the only help you'll need. Using practical examples, HTML5 Web Application Development by Example will develop your knowledge and confidence in application development.

What you will learn

  • Build your first HTML5 application in next to no time
  • Develop fun applications and games
  • Learn about UI and UX using the new features in CSS3
  • Create dynamic, responsive applications that will work on any device
  • Use the top features in HTML5 to create fun, useful applications

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : Jun 25, 2013
Length: 276 pages
Edition : 1st
Language : English
ISBN-13 : 9781849695954
Vendor :
Microsoft
Languages :
Tools :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
OR
Modal Close icon
Payment Processing...
tick Completed

Billing Address

Product Details

Publication date : Jun 25, 2013
Length: 276 pages
Edition : 1st
Language : English
ISBN-13 : 9781849695954
Vendor :
Microsoft
Languages :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
$19.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
$199.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts
$279.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just $5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total $ 164.97
HTML5 Web Application Development By Example : Beginner's guide
$48.99
HTML5 Data and Services Cookbook
$60.99
Learn HTML5 by Creating Fun Games
$54.99
Total $ 164.97 Stars icon

Table of Contents

12 Chapters
1. The Task at Hand Chevron down icon Chevron up icon
2. Let's Get Stylish Chevron down icon Chevron up icon
3. The Devil is in the Details Chevron down icon Chevron up icon
4. A Blank Canvas Chevron down icon Chevron up icon
5. Not So Blank Canvas Chevron down icon Chevron up icon
6. Piano Man Chevron down icon Chevron up icon
7. Piano Hero Chevron down icon Chevron up icon
8. A Change in the Weather Chevron down icon Chevron up icon
9. Web Workers Unite Chevron down icon Chevron up icon
10. Releasing an App into the Wild Chevron down icon Chevron up icon
A. Pop Quiz Answers Chevron down icon Chevron up icon
Index Chevron down icon Chevron up icon

Customer reviews

Rating distribution
Full star icon Full star icon Full star icon Full star icon Half star icon 4.3
(4 Ratings)
5 star 75%
4 star 0%
3 star 0%
2 star 25%
1 star 0%
Arun Mahendrakar Nov 22, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have seen a few other books on this topic, but this one starts from the very basics and takes the reader through some of the very advanced concepts.The first three chapters work on improving the user-experience and the feature set of a 'to-do' list. The author's style of explanation is quite lucid and easily understandable.The next two chapters throw light on HTML5 Canvas, showing a glimpse of the power that the Canvas holds.Chapters 6 and 7 show the HTML5 Audio element. At then end of these chapters, you will have become a piano-man!Chapter 8 talks about making server calls using jQuery Ajax. This chapter could have been a bit more elaborate with code samples for making post and delete calls on the server (although the challenge there is to have a server-side component for the application).The information provided regarding Web Workers is also very nice.The highlights of the book are:* The piano game in chapter 7* The photo pad app in chapter 5* The working details of Web Worker in chapter 9All-in-all, if you're new to the subject and want to learn a good deal on this topic, this is a good book.
Amazon Verified review Amazon
Amazon Customer Nov 15, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Are you looking for a book to know more about HTML5? Do you get bored reading tons of theory and not many "hand on lab"?Then don't search more and read this book.It teach you what HTML5 brings driven by examples. You'll find out how to build classical 'todo list' from scratch, following an incremental development to enhance it with more and more features and also making it beautiful with the new CSS3 properties.But it isn't all, you will be instructed with the HTML5 canvas and APIs (File, Audio, ...) and how to make it available offline, so it allows you to craft web applications close to desktop ones.
Amazon Verified review Amazon
SuJo Oct 09, 2013
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book really had me thinking about HTML5 in a whole new way. First I respect any coder who uses UML or Flowcharts to delegate the thinking process involved in organized code. I really like the Pop Quiz exercises to test my new found knowledge, the applications in the book are usable and not very difficult to follow.Having knowledge of JavaScript(jQuery), HTML, and CSS will help you with HTML5.A few things to mention:I really liked the photo manipulation, black and white, sepia, etc.The basic drawing application is really great, it shows you how things work and what you can expect.Canvas is really powerful, it's not limited to what this book shows it's uses. You can use it to make HTML5 Games!Don't skip anything and start from page 1, the author builds on the knowledge you learn from the start. Excellent book at a reasonable price to get you started.[...]
Amazon Verified review Amazon
E. Powell Feb 14, 2015
Full star icon Full star icon Empty star icon Empty star icon Empty star icon 2
Ordered this because it's advertised for beginners. It's not. You have to have a strong foundation in HTML and CSS to jump into this book.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.