Website Development I

Course Info Class Notes Resources Student Websites

Class No. 4:

CSS Selectors and the span and div Elements

To add class and id attributes to HTML elements and use those as CSS selectors.

Web Programming book reading for THIS class

Web Programming book reading for NEXT class

Additional References

It wasn’t clear to some of you that I had created a starter file for Tuesday’s exercise.

  1. Open the UltraEdit editor on your computer.  This should open a blank window that is ready for editing.
  2. Leave the editor open and click here to open the starter code in your Microsoft Edge browser.
  3. Type CtrlU to view the source code for the starter code page.
  4. Click anywhere in the browser window and type CtrlA to select all of the code.
  5. Type CtrlC to copy the code.
  6. Return to UltraEdit and type CtrlV to paste the code into the blank editor window.
  7. Type CtrlS to save your copy of the starter code to your dropbox.  Name the file as you see fit.
  8. Open the file you just saved in Microsoft Edge to ensure that you have saved it correctly.

Today’s exercise continues along the same vein.

Do you have questions or issues from our last class or the readings?


Selector Types – Revisited

Tag Selectors

We worked with these in our last class.


Class Selectors

A class is applied to a tag using the class attribute.

Example

<p class="reverse">This paragraph is rendered in "reverse video", 
    that is, with a dark background and light-colored letters.</p>

This paragraph is rendered in "reverse video", that is,
with a dark background and light-colored letters.

Applying Classes to Elements

Styling Classes with CSS

Syntax

.classname {
  1st-property: 1st-property’s-value;
  2nd-property: 2nd-property’s-value;
}

Notice the dot or period (.) before the class name.


Dean, Web Programming, p. 80

.time-format {
  font-family: monospace, sans-serif ;
  font-size: 18pt ;
  font-weight: bold ;
  color: red ;
}

<p>20:36 hours = <span class="time-format">8:36 PM</span></p>

<p>20:36 hours = <em class="time-format">8:36 PM</em></p>

20:36 hours = 8:36 PM

20:36 hours = 8:36 PM

20:36 hours = 8:36 PM


ID Selectors

#idname {
  1st-property: 1st-property’s-value;
  2nd-property: 2nd-property’s-value;
} 

Notice the pound or hash sign (#) before the ID’s name.


Dean, Web Programming, p. 83

#message {
  font-variant: small-caps ;
  font-weight: bold ;
  color: blue ;
}

<p id="message">Any situation not covered by the above rules will be addressed as it occurs by the officer in charge.</p>

Any situation not covered by the above rules will be addressed as it occurs by the officer in charge.


span and div Elements

These elements do not have built-in renditions.


Dean, Web Programming, p. 85


Dean, Web Programming, p. 85

<div> and <span> are both container elements


Today’s Exercise

Note:  Today’s exercise is complex.  Like last week, I do not expect you to finish this exercise in one day.  We will continue working on it in our next class.  Some of the styling will be easier to do when we look at additional types of selectors and other HTML elements.

Goal:  To render PRO Manual page 47 in the browser so that it looks as close as possible to the way it looks in the manual.

Procedure:

  1. Look at page 47 of the PRO Manual and notice that:
    1. The page header after the page number, “|CTEC: Business & Computer education,” is in a light gray color.  (“Education” should also be capitalized here.)
    2. The main page title at the top of the page, “CTEC: BUSINESS & COMPUTER EDUCATION,” is in white text.
    3. The page text is enclosed in a light gray border.
    4. The “Foundation Classes” section is indented.
    5. The page has additional text formatting characteristics, but ignore the icon in the page header and the CTEC logo image for now.
  2. Open the UltraEdit editor on your computer.  This should open a blank window that is ready for editing.
  3. Leave the editor open and click here to open the starter code in your Microsoft Edge browser.
  4. Click anywhere in the browser window and type CtrlA to select all of the code.
  5. Type CtrlC to copy the code.
  6. Return to UltraEdit and type CtrlV to paste the code into the blank editor window.
  7. Type CtrlS to save your copy of the starter code to your dropbox.  Name the file as you see fit.
  8. Open the file you just saved in Microsoft Edge to ensure that you have saved it correctly.
  9. Attempt to implement these formatting characteristics using CSS.  Here are the CSS properties I used in my version that that you might also want to use.
  10.       font-family: Verdana, Arial, sans-serif ;
          width: 600px ;
          font-style: italic ;
          font-weight: bold ;
          color: white ;
          color: RGB( 121, 143, 156 ) ;  (this is the color of the grayish blue text)
               or  color: lightblue ;
          background-color: RGB( 121, 143, 156 ) ;
               or  background-color: lightblue ;
          border: 2px solid RGB( 121, 143, 156 ) ;
               or  border: 2px solid lightblue ;
          border-radius: 0 10px 10px 0 ;
          float: left ;   /* for the student icon */
          float: right ;  /* for the CTEC logo */
          height: 50px ;
          margin-right: 0.5em ;
  11. You will need the <div> and <span> tags to do a really good job on this exercise.  Note where I have included these in the starter code and assigned each an ID.

To see what can be done, compare page 47 of the PRO Manual with my HTML version of this page.


 


This is Class No. 4.  It was last modified on Saturday, October 21, 2023 at 4:38 PM.  Copyright © 2010-2024 by Jesse M. Heines.  All rights reserved, but may be freely copied or excerpted for educational purposes with credit to the author.