The CSS
Cascading style sheets are what define how DHTML
elements look and behave. For information on style sheets visit our
"How to Make Cascading Style Sheets" tutorial.
Without CSS, we wouldn't have any handles on the <div> tags to
which we can hang on to. Let's look at the example DHTML page again.
Each block has a set of attributes that specify how it looks and works.
Above, each DHTML block has a set of attributes
that control how the element looks and works. The text block has a position of 200 pixels
from the left and 250 pixels from the top. It also defines what type of font to use as
well as color. All this is done with inline style sheets. By adding a style attribute
with a list of style definitions enclosed in double quotes to a <div> tag,
we order the browser to take this block and display it how we want it. Below is what
the code of the text block looks like.
<div id="story"
style="position: absolute;
top: 250;
left: 200;
width: 400;
z-index: 1;
font-family: 'tahoma';
color: #333333">
A pleasing land of drowsy head it was,<br>
...
</div>
Notice how we had the style attribute span a
line for every definition. This is done just to increase readability. By using
the various CSS selectors and assigned values to describe the block, we define a
type of personality for the whole block. For a listing of the CSS selectors visit
our List of CSS Properties And Values reference.
Everything within the <div> tags is then limited to these characteristics.
Now what's the deal with the two sub blocks containing
the two sword images? The two sub blocks inherit the position attributes from the
larger block and are positioned relative to the larger block's position.
Below is the code for the two sub blocks.
- <!-- -------------CONTROL BLOCK------------- -->
-
- <div id="controls"
- style="position: absolute;
- top: 100;
- left: 700;
- width: 50;
- height: 300;
- Z-Index: 1;
- Visible: true"
>
-
- <div id="scrollup"
- style="position: absolute;
- top: 0;
- left: 0"
>
- <img src="up.gif" alt="Scroll Up">
- </div>
-
- <div id="scrolldown"
- style="position: absolute;
- top: 200;
- left: 0"
>
- <img src="down.gif" alt="Scroll Down">
- </div>
-
- </div>
Look at lines 12 and 19. Notice the <div> tags are
within another <div> tag which means any top or left values
given to the inner blocks will
use the outer block's position as the origin. That's because the inner <div> tags
of the controls element inherit the controls element's position.
Don't forget the hierarchy.
Now that you've had a taste of what part CSS has in DHTML,
you can go on to the next part which describes the "dynamic" part of dynamic HTML.