bbb Home |
Lesson 6 - Set up Game Page and Position Elements |
SUMMARYIn this lesson you will set up the game page and position the elements. You will use the style positioning properties to place the space ship, the score, and the start button on the screen. DISCUSSIONIn lesson 3 we used style to format a web page. In that lesson, we added style "inline" with the tag. Another approach for formatting an element using style is to give the element an ID and then define the style for the ID in <style> tags in the <head> section. Elements on a page can be given an ID. Because the ID is used to idenfity the element, each ID must be unique. In other words, there can only be one element with any given ID. It is analogous to social security numbers. Each of us has our own unique social security number. Referring to the example below, the <div> element on line 12 has been given the ID "divScore". We could use almost any name we want as long as it is unique. Lines 3 and 9 define a <style> section. Style properties are defined for ID's in the <style> section. The <style> section is nested between the opening and closing <head> tags. Lines 4 to 8 define the style properties for the element with the ID "divScore". Notice the # sign before the word "divScore". This # sign indicates that divScore is an ID. Between the opening bracket { on line 4 and the closing bracket } on line 8 we define the style properties for the ID. Notice that the format for defining properties is the same as when we defined them inline in lesson 3. The property is listed, followed by a colon, the value of the property, and the semi-colon to separate multiple properties.
Notice that properties can be on either the same or different lines. Line 6 shows that more than one property can be on one line. On lines 5 and 6, three new style properties are introduced: position, top, and left. When we want to position an element at a specific location on a page we need to assign a value of "absolute" to the position property. Then we can use the top and left properties to define the location of the top and left side of the element measured from the top and left of the screen. In the example, divScore is positioned 10 pixels from the top of the screen and 150 pixels from the left of the screen. EXAMPLE - ID's and Positioning
PRACTICE
GAME DEVELOPMENT
|
References |
©dfx interactive, inc. Contact us at bigbadbrain@bigbadbrain.com |