UMass Lowell Dept. of Computer Science

91.461 GUI Programming I

Fall 2015 Semester, Section 201

Prof. Jesse M. Heines

Notes for Class No. 5

Working with CSS Selectors

Tuesday, September 15, 2015

A video of this class is (or will be) posted at:   http://echo360.uml.edu/heines201516/guiprogramming1.html


Handouts and Materials


Openings / Announcements / Reminders

Reminder:  Assignment No. 3 is now posted

Modern JavaScript Meetup — Wednesday evening, September 30th, 6:00-8:00 PM, Wannalancit Mills, pizza served

The following people do not appear to have signed up on Piazza

The following people need to go into Piazza and change their name to their full first and last names, properly capitalized

Websites for experimenting with CSS mentioned at the very end of our last class

I really can’t believe this, but all 51 of you registered for this course have completed in Assignment No. 2 on time


Class Notes

Related reading for this class:  CSS3:TMM Ch. 6


Finishing Up Our Introduction to CSS

We moved pretty quickly through the introductory material, which is great

But just to emphasize a couple of things ...


CSS Comments


CSS Rules


[figure source:  CSS: The Missing Manual by David Sawyer McFarland, Figure 2-2, 2nd edition: page 33, 3rd edition: p. 38]

Review Questions

Revisiting CSS Reset

A CSS reset removes the built-in renditioning for common HTML elements allowing you to start with a “clean slate“

For students who already know a lot of CSS


Basic CSS Selectors

Tag (or Type or Element) Selectors

[For those interested:  I have written a function that uses this type of selector combined with a regular expression to automatically format all the line numbers within <em>...</em> tags when a page is loaded.  That function can be found here.]

ID Selectors

Code

CSS

Output

Generic or Class Selectors

<h2 class="arial">
  This is a level 2 heading in Arial.
</h2>
<style type="text/css">
  .arial { font-family: Arial }
</style>
<h2 class="arial italic">
  This level 2 is in Arial italics.
</h2>

Code

<p class="example">2130 hours = 9:30 PM</p>

CSS

.example {
  font-family: monospace, sans-serif ;
  font-size: 12pt ;
  font-weight: bold ;
  color: blue ;
}

Output

2130 hours = 9:30 PM


Styling groups of tags

h1, h2, h3, h4, h5, h6 {
  color: #8B0000;
}

Descendent selectors

pre em {
color: #FF6600;
}
Combining the two techniques above
code em, pre em {
  color: #FF6600 ;
}

Pseudo selectors

Attribute Selectors

img[title] —> all img tags that have a title element

input[type="button"] —> all buttons

a[href="http://jesseheines.com"] —> all a[nchor] tags that link to the default page on jesseheines.com

a[href^="http://jesseheines.com"] —>all a[nchor] tags that link to any page on jesseheines.com

filter operators

Child Selectors

:first-child
:last-child
:nth-child

:nth-child(odd)
:nth-child(even)

:nth-child(Nn+S) where N is the repeat factor and S is the starting child

Additional Selector Operators

means immediate descendents, which is very useful with nested lists

means sibling, that is directly following

and please note that there are even more pseudo selectors and more being added, but these are the basic ones


Formatting Text  (CSS:TMM, Chapter 6)

CSS Properties Reference

http://w3schools.com/cssref/default.asp


Review of Basic Concepts

Font Sizing

Words and Letters

Kerning Demonstration

Paragraph Spacing

Pseudo-Elements

Lists

McFarland CSS MM Fig. 6-10
[figure source:  CSS: The Missing Manual, by David Sawyer McFarland, Fig. 6-10, p. 134]

Note that when manipulating class names in JavaScript, the class name property is in camel case: className



This is document http://jesseheines.com:8080/~heines/91.461/91.461-2015-16f/461-lecs/lecture05.jsp.  It was last modified on Friday, August 26, 2022 at 4:09 PM.
Copyright © 2022 by Jesse M. Heines.  All rights reserved.  May be freely copied or excerpted for educational purposes with credit to the author.