CSS 3
CSS 3
Web Programming
Introduction to CSS – part 3
h1 {
letter-spacing: 3px;
}
h2 {
letter-spacing: -3px;
}
p.small {
line-height: 0.8;
}
p.big {
line-height: 1.8;
}
Monospace Courier New All monospace characters have the same width
Lucida Console
Styling with CSS
p {
Font Family }
font-family: "Times New Roman", Times, serif;
• If the name of a font family is more than one word, it must be in quotation
marks, like: "Times New Roman".
• More than one font family is specified in a comma-separated list
Styling with CSS
Font Style
• The font-style property is mostly
used to specify italic text.
• This property has three values:
• normal - The text is shown
normally
• italic - The text is shown in italics
• oblique - The text is "leaning"
(oblique is very similar to italic,
but less supported)
h1 {
font-size: 40px;
}
h2 {
font-size: 30px;
}
p {
font-size: 14px;
}
Styling with CSS
Font Size in Em
• To allow users to resize the text (in
the browser menu), h1 {
• Many developers use em instead of font-size: 2.5em; /* 40px/16=2.5em */
pixels. }
• The em size unit is recommended by
the W3C. h2 {
font-size: 1.875em; /* 30px/16=1.875em
• 1em is equal to the current font size. */
• The default text size in browsers is }
16px.
• So, the default size of 1em is 16px. p {
• The size can be calculated from pixels font-size: 0.875em; /* 14px/16=0.875em
to em using this */
}
formula: pixels/16=em
Original image
x% y% The first value is the horizontal position and the second value is the vertical. The top left corner is 0% 0%.
The right bottom corner is 100% 100%. If you only specify one value, the other value will be 50%. . Default
value is: 0% 0%
xpos ypos The first value is the horizontal position and the second value is the vertical. The top left corner is 0 0. Units
can be pixels (0px 0px) or any other CSS units. If you only specify one value, the other value will be 50%. You
can mix % and positions
body {
background: #ffffff url("img_tree.png") no-repeat right top;
}
• When using the shorthand property the order of the property values is:
• background-color
• background-image
• background-repeat
• background-attachment
• background-position
• It does not matter if one of the property values is missing, as long as the other ones are in this
order.
Styling with CSS
The CSS Box model
• All HTML elements can be considered as boxes.
• In CSS, the term "box model" is used when talking about design and layout.
• The CSS box model is essentially a box that wraps around every HTML element.
• It consists of: margins, borders, padding, and the actual content.
margin
padding