Introduction

This is a simple application for beginners that shows how to create a playground using HTML 5 and CSS tools. We know that HTML 5 is the advanced version of HTML. Basically HTML 5 can be used to develop 3D applications. This article is intended to help with the use of HTML5 tools to develop playground applications. CSS is the acronym for Cascading Style Sheet that is used for design. CSS defines how HTML elements are to be displayed. Canvas is an important tag of an HTML 5 that is used to show the image and text in an HTML 5 application. I hope this article helps to create playground applications using HTML 5 and CSS tools.
Step 1: First open an HTML editor such as Notepad.
wakakakakak.gif
Step 2: Create a Folder on a desktop.
folder.gif
Step 3: Open Visual Studio.
new.gif
webapplication.gif
Step 4: Add an HTML file to your web application.
html.gif
Step 5: Now in this step we add a CSS file that sets all properties of a canvas body. Through CSS we set color, size and font properties of a canvas body.
Code
  1. body
  2. {
  3. background: #333;
  4. color:Lime;
  5. font: 300 100.1% "Helvetica Neue";
  6. }
  7. #holder
  8. {
  9. height: 480px;
  10. left: 50%;
  11. margin: -240px 0 0 -320px;
  12. position:relative;
  13. top: 50%;
  14. width: 640px;
  15. }
  16. #copy
  17. {
  18. bottom: 0;
  19. font: 300 .7em "Helvetica Neue";
  20. position:relative;
  21. right: 1em;
  22. text-align: right;
  23. }
  24. #copy a
  25. {
  26. color:Green;
  27. }
Step 6: Now in this step we apply the style of the playground.
Code
  1. <style type="text/css" media="screen">
  2. body
  3. {
  4. margin: 0;
  5. padding: 0;
  6. text-align: center;
  7. }
  8. h1 {
  9. font-weight: 400;
  10. height: 10%;
  11. }
  12. #canvas
  13. {
  14. height: 732px;
  15. margin:20 auto;
  16. text-align:center;
  17. width: 1015px;
  18. background-color:Green;
  19. }
  20. #code
  21. {
  22. font-family: "Lucida Console", monospace;
  23. height: 4em;
  24. margin: 10px;
  25. padding: 0;
  26. width: 90%;
  27. }
  28. #run
  29. {
  30. font-size: 2em;
  31. }
  32. </style>
Step 7: Add a JavaScript file to the application. The T1.js file provides the functionality of dynamically move a playground. Set a D1.css that sets the color, size and font properties of a playground body.
Code
  1. <link rel="stylesheet" href="D1.css" media="screen"/>
  2. <script type="text/javascript" src="Scripts/T1.js"></script>
body.............gif
Step 8: Now in this step we define an onclick function that is used when the circle is clicked to perform an action.
Code
  1. (btn.onclick = function ()
  2. {
  3. ctx.clear();
  4. ctx.rect(0, 0, 640, 480, 10).attr({ fill: "#66ff99", stroke: "none" });
  5. try
  6. {
  7. (new Function("ctx", "window", "document", cd.value)).call(ctx, ctx);
  8. }
  9. catch (e)
  10. {
  11. alert(e.message || e);
  12. }
Step 9: The complete code of the application is given below.
Code
  1. <html>
  2. <head>
  3. <title>Tom application</title>
  4. <link rel="stylesheet" href="D1.css" type="text/css" media="screen"/>
  5. <script type="text/javascript" src="Scripts/T1.js"></script>
  6. <style type="text/css" media="screen">
  7. body
  8. {
  9. margin: 0;
  10. padding: 0;
  11. text-align: center;
  12. }
  13. h1
  14. {
  15. font-weight: 400;
  16. height: 10%;
  17. }
  18. #canvas
  19. {
  20. height: 732px;
  21. margin:20 auto;
  22. text-align:center;
  23. width: 1015px;
  24. background-color:Green;
  25. }
  26. #code
  27. {
  28. font-family: "Lucida Console", monospace;
  29. height: 4em;
  30. margin: 10px;
  31. padding: 0;
  32. width: 90%;
  33. }
  34. #run
  35. {
  36. font-size: 2em;
  37. }
  38. </style>
  39. window.onload = function ()
  40. {
  41. var ctx = Raphael("canvas", 640, 480),
  42. btn = document.getElementById("run"),
  43. cd = document.getElementById("code");
  44. (btn.onclick = function ()
  45. {
  46. ctx.clear();
  47. ctx.rect(0, 0, 640, 480, 10).attr({ fill: "#66ff99", stroke: "none" });
  48. try
  49. {
  50. (new Function("ctx", "window", "document", cd.value)).call(ctx, ctx);
  51. }
  52. catch (e)
  53. {
  54. alert(e.message || e);
  55. }
  56. </script>
  57. </head>
  58. <body>
  59. <h1>Developed Playground Using HTML5</h1>
  60. <div id="canvas" style="background-color: #8080FF"></div>
  61. </body>
  62. </html>
Step 10: Press Ctrl + F5 to run the application in a browser.
Output
p.gif
r.gif
q.gif
Resources
Here are some useful resources :