W02 02 MoreCSS
W02 02 MoreCSS
Margin
Border
Margin edge
Padding
Border edge
Content
Padding edge
Content edge
Box model
• CSS box model à box around an HTML element with the following
components: margin, border, padding, content
• Box model allow us to define space between different elements
• Four sections can be identified:
• Content à what lies in the middle of the box (text, image, etc.)
• Padding à surrounds the content
• Border à surrounds the padding and represents the box border
• Margin à surrounds the border
Margin
Border
Margin edge
Padding
Border edge
Content
Padding edge
Content edge
Box model padding and margin
• You can adjust individual padding/margin properties by using:
• padding-bottom, padding-left, padding-top, padding-right
• margin-bottom, margin-left, margin-top, margin-right
• The margins, borders, padding, and background properties of block
elements (e.g., body, p, etc.) are not passed to their child block-level
elements
Shorthand property
• Shorthand Property à allows you to specify several properties by using
only one
• If you don’t specify one of the properties a default value will be used
• Commonly used shorthand properties
• background
• font
• list-style
• margin
• border
• padding
• Example à border: 2em solid green;
Background properties
• background-color
• background-image à location of image
• background-repeat à how image repeats. Possible values for repetition:
• no-repeat à one instance of the image
• repeat à tile
• repeat –y à repeats on the y-axis (repeat –x à repeats on the x-axis)
• background-attachment à indicates attachment of the image to the
containing element. Possible values are:
• scroll à default value
• fixed à image will stay stationary as the scrolling takes place
• background-position à top, bottom, center, left, right (combinations
valid)
Generic font families
• sans-serif à (e.g., Verdana, Helvetica, Arial)
• serif à (e.g., Times New Roman, Georgia, Times)
• monospace à (e.g., Courier, MS Courier New)
• cursive à (e.g., Lucida Handwriting)
• fantasy à (e.g., Whimsey, Comic Sans)
• Browser can choose an available font from that family