UMass Lowell Dept. of Computer Science

91.461 GUI Programming I

Fall 2015 Semester, Section 201

Prof. Jesse M. Heines

Notes for Class No. 9

Working with Margins, Padding, and Borders

Tuesday, September 29, 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


HTML5 & JS End User Monitoring / Overview of GruntJS

Questions or issues with Assignment No. 4 on GitHub?


Class Notes

Related reading for this class:  CSS3:TMM Ch. 4, 5, & 7

Margins, Padding, and Borders  (CSS:TMM Chapter 7)

The CSS Box Model


[source of both figures:  CSS: The Missing Manual, by David Sawyer McFarland, Fig. 7-1, p. 152 (2nd ed.), p. 194 (3rd ed.)]

Additional diagrams and demos

Margin and padding shorthand

Margins and padding and their behaviors with various blocks

Note:  The excerpts below are from Martin Luther King, Jr.’s “I Have a Dream” speech, delivered August 18, 1963, at the Lincoln Memorial in Washington, D.C.  For a recording and full transcript of this speech, please see http://www.americanrhetoric.com/speeches/mlkihaveadream.htm.

Dealing with Units

Doubling (or Colliding) Margins and Collapsing Margins

Margin values can be negative, but padding values cannot

Remember that when width and height are expressed as percentage values, those percentages are based on the values “of the style's containing element” (p. 154)


Controlling text overflow  (Fig. 7-10/7-14, p. 168/218, at the right)


Floating Elements

Floating images (using the img tag) with the align attribute is deprecated, but floating images with CSS is not always completely analogous

Source order (p. 171/221)

Backgrounds, Borders, and Floats (p. 172/222)

CSS:TMM, Fig. 7-12
[figure source:  CSS: The Missing Manual, by David Sawyer McFarland, Fig. 7-12/7-16, p. 172/222]

To stop the wrapping caused by floats, use clear to force the element to drop below the previously floated element

See the wonderful tutorials in the book


CSS Inheritance  (CSS:TMM Ch. 4)

Classic inheritance vs. CSS inheritance

General rules for CSS inheritance  (CSS:TMM pp. 83-85/95-97)

CSS:TMM Appendix A lists all CSS properties and indicates which get inherited and which do not starting on page 463/563


Managing the Cascade  (CSS:TMM Ch. 5)

The previous chapter and exercise introduced the cascade, this one goes into more detail

As you saw in the previous exercise, inherited styles accumulate

Inheritance rules

Specificity  (CSS:TMM p. 96/108)

Figure 5-3
[figure source:  CSS: The Missing Manual, by David Sawyer McFarland, Fig. 5-3, p. 97/109]

Other issues

It is impossible to memorize all these rules



This is document http://jesseheines.com:8080/~heines/91.461/91.461-2015-16f/461-lecs/lecture09.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.