CSC336-WT Lec7 Slides
CSC336-WT Lec7 Slides
h1 {
Example
color: red;
p {
text-align: right; font-family: Arial;
font-size: 20px;
} }
Property Value
Common CSS Properties
• color
• text-align
• font-family, font-size, font-weight
• width, height
• margin, padding
• border
•...
How To Add CSS
Three Ways to Insert CSS
There are three ways of inserting a style sheet:
• External CSS
• Internal CSS
• Inline CSS
Example: Inline CSS
style.html
• <h1 style="color: blue;">Hello</h1>
• <h1 style="color: red;">Hello</h1> <!-- springgreen -->
• <h1 style="color: blue; text-align: center;">Hello</h1>
• <body style="color: blue; text-align: center;">
Typeface (Font Family)
• A typeface is a distinctive design that's common to any related set of
letters, numbers and symbols.
• What’s the difference between a typeface and a font?
o the two terms are interchangeable.
o Font: A font is a particular implementation of a typeface, meaning the
typeface as rendered with a specific weight, size and style.
o Typeface: The typeface gives each character a shape and thickness that's
unique to the typeface
o Helvetica is a typeface; bold 16-point Helvetica is a font.
font: weight + size + typeface
Example: font: bold 40px sans-serif;
Typeface (Font Family)
1. Serif fonts have a small stroke at the edges of each letter. These
subtle appendages give the typeface a traditional, classy look, but
they can get lost when displayed on a screen at small sizes.
2. Sans-serif fonts have clean lines (no small strokes attached). They
create a clean modern and minimalistic look that’s well suited to
screen text, particularly at small sizes.
3. Monospace fonts - here all the letters have
the same fixed width, so skinny letters such
as i and l take up as much space as wider
letters such as m and w. They create a
mechanical look.
4. Cursive fonts are designed to resemble human
handwriting e.g. handwritten pen or brush
writing.
5. Fantasy fonts are decorative/playful fonts
Difference Between Serif and Sans-serif
Serif works best for headings and other text set at large sizes;
Cursive best for short bits of text that require elegance or playfulness e.g. scripts
Fantasy should be used only when a special effect is required (such as being extra thick).
Example: External CSS
h1 {
color: blue;
text-align: left;
font-family: Arial, sans-serif;
font-size: 28px;
font-weight: normal;
}
CSS Box Model
• All HTML elements can be considered as boxes.
Table Border
table {
border: 1px solid black;
border-collapse: collapse;
}
td, th {
border: 1px solid black;
padding: 5px;
}
Identifying Elements
• div
• span
• id
• class
<div>
Hello, World!
</div>
div {
background-color: orange; <!-- blue -->
width: 200px; <!– 100px -->
height: 200px; <!– 400px -->
padding: 20px;
margin: 20px;
border: 3px dashed black;
}
ID, class
<body>
<h1 id="foo">Heading1</h1>
<h1 id="bar">Heading2</h1>
<h1 class="baz">Heading3</h1>
</body>
• #fo
• #bar
• .baz
Example leading to Specificity
h1 {
color: red;
}
#foo {
color: blue;
}
Specificity (Precedence)
1. inline
2. id
3. class
4. type
Specificity
<div id="foo">
Hello!
</div>
div {
Hello!
color: blue;
}
Specificity
<div id="foo">
Hello!
</div>
div { Hello!
color: blue;
}
#foo {
color: red;
}
Specificity
<div id="foo">
Hello!
</div>
#foo { Hello!
color: red;
}
div {
color: blue;
}
Lesson Learning Outcome (LLOs)
• CSS rule
• Common CSS Properties
• Inline Vs Internal Vs External CSS
• Typeface Vs Font
• CSS Box Model
• Specificity