Web Engineering: Font, Text & Background
Web Engineering: Font, Text & Background
Lecture 07
Font, Text & Background
(CSS - II)
1
Block-Level Elements
• A block level element in HTML create a “block” or
“box”.
– Components of a box
• Content
• Padding
• Border
• Margins
The Box
Margin
Element Content
Padding
Border
• Output:
This text is rendered in either georgia,
garamond, or the default serif font
depending on which font you have at your
system.
Generic Font Family
• These are the generic name values for the
font-family property, followed by an example
of each that the browser might select from
the user’s system fonts:
Generic font-family Names Example
serif Times New Roman
sans-serif Arial
cursive Zapf-Chancery
fantasy Western
monospace Courier
12
font-style
• <p style="font-style: italic;">
This text will be rendered in italic style.
</p>
• Output:
This text will be rendered in italic style.
• Possible Values:
normal, italic, oblique(more slanted than
normal)
13
font-size
• <p style="font-size: 20pt;">
This font size is 20 pixels.
</p>
• Output:
This font size is 20 points.
• Possible values:
px, small, xx-small, x-small, medium, large, x-
large, xx-large or in %
14
font-weight
• <p style="font-weight: bold;">
This font is bold.
</p>
• Output:
This font is bold.
• Possible values:
normal, bold, bolder, lighter, 100, 200, 300, 400,
500, 600, 700, 800, 900
15
font-variant
• <p style="font-variant: small-caps;">
This text will be rendered in small caps. </p>
• Output:
THIS TEXT WILL BE RENEDERED AS
SMALL CAPS.
• Possible values:
normal, small-caps
16
line-height
• The line-height property is used to set the
vertical distance between the baselines of
adjacent lines of text.
17
line-height
• <p style=“line-height: 120%;”>
The line-height property is just spaces the lines.
and this is the second line.</p>
• Output:
The line-height property is just spaces the lines.
and this is the second line.
• Possible Values:
normal or any number with %, px or em unit
18
CSS Text Formatting
• You can set following text properties of an
element:
The color property is used to set the color of a
text.
The letter-spacing property is used to add or
subtract space between the letters.
The word-spacing property is used to add or
subtract space between the words.
The text-indent property is used to indent the
text of a paragraph.
The text-align property is used to align the text
of a document.
The text-decoration property is used to
underline, overline and strikethrough text.
The text-transform property is used to
capitalize text or convert text to uppercase or
lowercase letters.
The text-shadow property is used to set the
text shadow around a text.
The white-space property is used to control
the flow and formatting of text.
20
color
• <p style=“color: red;” >
This text will be written in red.
</p>
• Output:
This text will be written in red.
• Possible values:
any color name in any valid format.
21
letter-spacing
• <p style=“letter-spacing: 5px;” >
This text is having space between letters.
</p>
• Output:
This text is having space bet
w e e n l e t t e r s.
• Possible values:
normal or a number.
22
word-spacing
• <p style=“word-spacing: 5px;” >
This text is having space between words.
</p>
• Output:
This text is having space between words.
• Possible values:
normal or a number.
23
text-indent
• The text-indent property is used to indent
only the first line of text within an element.
24
text-indent
• <p style=“text-indent: 1cm;” >
This text will have first line indent by 1cm.
and this line will remain at its actual position.
</p>
• Output:
This text will have first line indent by 1cm.
and this line will remain at its actual position.
• Possible values:
% or a number.
25
text-align
• <p style=“text-align: right;” >
This will be right aligned.
</p>
• Output:
This will be right aligned.
• Possible values:
left, right, center, justify
26
text-decoration
• <p style=“text-decoration: underline;” >
This will be underline.
</p>
• Output:
This will be underline.
• Possible values:
none, underline, overline, line-through, blink
27
text-transform
• <p style=“text-transform: uppercase;” >
This will be in uppercase.
</p>
• Output:
THIS WILL BE IN UPPERCASE.
• Possible values:
none, capitalize, uppercase, lowercase
28
white-space
• The white-space property is used to specify
whether the blank space between words
both horizontally and vertically is collapsed
to a single character space or is retained
and preserved as is.
29
white-space
• <p style=“white-space: pre;” >
This text has a line break
and the white-space pre setting tells the browser.
</p>
• Output:
This text has a line break
and the white-space pre setting tells the browser.
• Possible values:
normal, pre,
30
text-shadow
• <p style=“text-shadow: 4px 4px 8px blue;” >
If your browser supports the css text-shadow
property, this text will have a blue shadow.
</p>
• Output:
• Possible values:
numbers
31
CSS background Properties
• You can set background of various HTML
elements:
The background-color property is used to set the
background color of an element.
The background-image property is used to set the
background image of an element.
The background-repeat property is used to control
the repetition of an image in the background.
The background-position property is used to
control the position of an image in the background.
The background-attachment property is used to
control the scrolling of an image in the background.
background-color
• <p style=“background-color: yellow;” >
This text has a yellow background. </p>
• Output:
• Possible values:
any color in a valid format.
33
background-image
• <table style=“background-image:url(images/css.gif);” >
<tr><td>
this table has background image which repeats multiple
times.
</td></tr>
</table>
• Output:
• Possible values:
any image with valid format
34
background-repeat
• <table style=“background-image: url(images/cat.gif);
background-repeat: no-repeat; ” >
<tr><td>
by default background-repeat property have repeat value.
</td></tr>
</table>
• Output:
• Possible values:
repeat, repeat-y, repeat-x, no-repeat
35
background-size
• <table style=“background-image: url(images/cat.gif);
background-repeat: no-repeat;
background-size: 200px 200px; ” >
<tr><td>
background-size property is used to expand the background
image.
</td></tr>
</table>
• Output:
• Possible values:
repeat, repeat-y, repeat-x, no-repeat
36
background-position
• <table style=“background-image: url(images/css.gif);
background-position: 100px 200px; ” >
<tr><td>
this table has background image positioned 100 pixels away
from the left and 200 pixels from the top.
</td></tr> left center
• Possible values:
X% Y%, top left, Xpx Ypx
37
background-attachment
• <p style=“background-image:url(images/css.gif);
background-attachment: fixed; ” >
This paragraph has fixed background image.
</p>
• Output:
• Possible values:
fixed, scroll
38