HTML, CSS & Javascript: Introduction


This website gives an introduction to Game Design. This webpage forms the 2nd introductory page in the series - providing a more detailed overview of some basic HTML, Javascript and CSS techniques that will be used throughout this website. The other pages on this website cover: HTML5 Canvas, an object of the HTML5 DOM that forms the stage for games on the web; Javascript, the language best suited for creating games on the HTML5 Canvas; and developing CSS techniques (which is a minor feature of game development).

Introduction

1. Introduction To This Webpage

2. A Step-By-Step Overview

The Steps

2: Create A Styled Button (CSS)

3. Create An "Event Listener" For An Event (Javascript)

4: Use The "Event Listener" To Change The CSS Style (Javascript)

5: Transition Between The Two CSS styles (CSS)

6: Conclusion

7: Footnotes

[1] "open" in the details tag is required as some browsers have already added the "hide/reveal" functionality. That is, in the coming years, the "hide/reveal" functionality that I am adding will be a default function of the detail tag.

[2] That is, you write the text as you normally would - i.e. the text is always there on the webpage - but the "display:none" CSS style ensures that it is hidden from view. The CSS for these tags would simply read "details{ display:none; }" (or "details.reveal{ display:none; }" for "details" tags with the class "reveal" - if you needed to be more specific, i.e. were using the details tag for other sections of that you did not want to hide/reveal (and so would give them a different class name)).

[3] Buttons are Objects in HTML - that is, they are containers that have a range of pre-specified "properties". A little later, we will be using these pre-specified properties to allow our buttons to perform actions. To allow us to see the properties an Object has, there is a Javascript function getAllProperties() that I have running on this page. It returns a list of any Objects' properties. So, for example, we will, later, give one of these button Objects an id button0. Using "command+option+i" (for a mac) or "F12" (for windows) we can bring up the console window. If you copy and paste getAllProperties(button0) into the command line on the console, you will see what properties a generic button Object contains. Impressive, no? (You can see that one of the properties available to us is "addEventListener", which we will use in the next section). This is an example of the aspects of a web browser as an interpreter that runs "behind the scenes", and which gives webpage creators an enormous range of features to control.

[4] The CSS code can be included directly in the HTML page (by placing it between <style> css code here </style> tags) but it is customary to write it in a separate file, getting the HTML page to read it by including a link to the file in the head of the HTML page (for example, I have this statement in the head of this page that you are reading: <link rel='stylesheet' type='text/css' href='css/gameDesignIntroduction.css'>). The same is true of Javascript code - except that Javascript code written directly in a HTML page is placed in "script" tags, like this: <script> javascript code here </script>, and, if written in a separate file, is usually linked at the bottom of the HTML page, just before the closing "body" tag, as I have done on this page, like so: <script src="js/gameDesignIntroduction.js"></script>