The Computer Gal Logo - Laptop with coffee and plants
Exercise: Two Little CSS Layers
The Computer Gal on Facebook
Ask to receive tips and handouts to your email.

Purpose: to visualize how a layer works

  1. To make this exercise easier to do, we will use an internal style sheet
    Of course, this is the NOT best practices of external style sheets.
    Do This:
    - Create a new, basic HTML page in Dreamweaver.
    - Save the file as PracticeFiles folder/CSSPositioning.html
  2. Start your styles
    Do This:
    In the <head>, enter
       <style type="text/css">
          <!--
          -->
       </style>
    Comments
    - This is how you start internal styles.
    - All the internal styles should be inside theses tags.
  3. Create a style for an outer layer
    Enter This
       #OuterLayer
       {
           background: #990000; - or choose a color you like!
       }
    Comments:
    - All the rest of the style information will be between the <!-- and -->.
    - That is a comment.
    - Styles are in comments so they will be ignored by old browsers, which cannot interpret styles correctly.
    - The background color will help you see the layer.
    - A "style" is the description of a "layer."
  4. Create a style for an inner layer
    Enter This:
      #InnerLayer
      {
          background: #009900; - or choose a second color you like!
      }
    Comments:
    - This code goes below the code for the OuterLayer, but inside the code created in #2.
  5. Insert two layers on the page, using the styles you just created
    Enter the following after the <body> tag:
       <div id="OuterLayer"></div>
       <div id="InnerLayer"></div>

    What do the layers look like? Why is that (Hint: remember what happened in the One Little CSS Layer exercise)
  6. Add a border property to each layer
    border: 1px solid #000000;
    How many layers do you see?
  7. Add a height property to each layer
    height: 50px;

    Why isn't one layer inside the other layer?
  8. Put the Inner Layer inside the Outer Layer
       <div id="OuterLayer">
          <div id="InnerLayer"></div>
       </div>
    What do you see?
  9. Reduce the size of the inner layer
      height: 20px;
    How is the inner layer positioned?
  10. Increase the height of the inner layer to 100px
      height: 100px;
  11. Add padding to the Outer Layer
      padding: 10px;

    Look at the page in IE6, IE7 and Firefox. Are they different?
  12. Change the position of the inner layer to absolute
      position: absolute:
      top: 20px;
      left: 0px;

    What happened?
  13. Add positioning to the Outer Layer
    position: absolute;

    Look at the page in IE6, IE7 and Firefox. Are they different?
  14. Change the positioning and the top

Notice that after we placed the layers on the page, we only changed the styles!

 

Nora McDougall | Missoula, Montana 59801 | 406.253.4045 | Contact Nora
© 2010, Nora McDougall-Collins