CSS in Practice
CSS in Practice
What is CSS?
• Example: my homepage
• Another example:
http://www.w3schools.com/css/demo_default.htm (.html)
2
Multiple Ways to Define Style
• Examples: http://www.w3schools.com/html/html_styles.asp
3
Multiple Styles Cascade Into One
4
CSS Style Rule
property names
declarations
p{
font-size: x-large ;
background-color: yellow
}
5
Selector Strings
• Type selector:
– Element type, such as body, p, hr, etc.
• See previous example
– Multiple element types using the same style are
separated by comma
• h1, h2, h3, h4, h5, h6 {background-color:purple}
• ID selector:
– #p1, #s1 {background-color: blue}
– <p id=“p1”> … </p>
– <span id=“s1”>…</span>
– id values are case-sensitive
6
Sector Strings, Continue …
• Class selector:
– .myitalic {font-style: italic}
– .myred {color: red}
– <span class=“myitalic myred”> … </span>
– class values are case sensitive
– multiple classes can be applied, separated by space
– All but a few elements, such as html, head, and elements
that appear as content of head, have the class attribute
• CSS comments
/* This is a comment */
p{
text-align: center;
/* This is another comment */
color: black; font-family: arial
}
8
How to Insert a Style Sheet?
9
CSS Basics
• Background
• Text
• Font
• Border
• Outline
• Margin
• Padding
• List
• Table
10
CSS Advanced
• CSS dimension
• CSS classification
• CSS positioning
• CSS pseudo-class
• CSS pseudo-element
• CSS media types
11
Font
12
How to Select a Font Family?
• Rules-of-Thumb
– Don’t use more than 3-4 fonts on any one page
– Don’t change the font in mid sentence unless you
have a very good reason
– Sans-serif for online, serif for print
– Monospace for typewriter and code
– Script and fantasy for accents
• Sans-serif fonts are the basis of your site, for
example:
– Arial, geneva, helvetica, lucida sans, trebuchet,
verdana
– Verdana is a font family that was actually invented
for use on the web
13
Selecting Font, Continue
14
Case Study
• Liquid layouts:
– The width of the entire page is flexible depending
upon how wide the viewer’s browser is
15
Case Study
• Steps:
– Draw your layout
– Create and style a Container element
– Use a Headline Tag for the Header
– To get 3 columns, start by building 2 columns
– Then add 2 columns inside the wide second column
– Add in the Footer
– Add in your personal style and content
16
Free Web Templates
• https://www.freewebtemplates.com/
• https://www.os-templates.com/free-website-templates
17