Title: Cascading Style Sheets
1Cascading Style Sheets
http//www.w3.org/Style/CSS/
2Midterm 1
3Matching
- 1-J
- 2-E
- 3-F
- 4-G
- 5-H
- 6-I
- 7-C
- 8-D
- 9-A
- 10-B
4 Multiple choices
- 1. C
- 2. b
- 3. a
- 4. b
- 5. d
- 6. c
- 7. c
- 8.c
- 9. c
- 10.
5SQL
- 3.1
- Team TeamID (PK) ConferenceID(FK)
- Conference ConferenceID (PK)
- One to many relationship
- ChildTeam
- ParentConference
6SQL
- 3.2
- Select teamID, teamName, RPI, ranking
- From Team
- Where conferenceID 1
7SQL
- 3.3
- Select Team.TeamName, Team.RPI,
Conference.ConferenceName - From Conference inner join team on
Conference.ConferenceID Team.TeamID - Where ranking lt 10
8- 3.4
- Select Team.TeamName, Team.RPI, Team.Ranking
- From Conference inner join team on
Conference.ConferenceID Team.TeamID - Where Conference.ConferenceNameBig Ten
9- 3.5
- TotalTeam ConferenceID
- 2 1
- 1 2
- 2 3
- 1 5
103.6
113.7
123.8
13Example of HTML
- lt!DOCTYPE html PUBLIC "-//W3C//DTD HTML
4.01//EN"gt - lthtmlgt ltheadgt lttitlegtMy first Web sitelt/titlegt
lt/headgt - ltbodygt
- lt!-- Site navigation menu --gt
- ltulgt
- ltligtlta href"index.html"gtHome pagelt/agt
- ltligtlta href"musings.html"gtMusingslt/agt
- ltligtlta href"town.html"gtMy townlt/agt
- ltligtlta href"links.html"gtLinkslt/agt
- lt/ulgt
- lt!-- Main content --gt
- lth1gtMy first styled pagelt/h1gt
- ltpgtWelcome to my first page!
- lt/bodygt
- lt/htmlgt
14Result
15Adding color
- lt!DOCTYPE html PUBLIC "-//W3C//DTD HTML
4.01//EN"gt - lthtmlgt
- ltheadgt
- lttitlegtMy first web pagelt/titlegt
- ltstyle type"text/css"gt
- body
- color purple
- background-color d8da3d
- lt/stylegt
- lt/headgt
-
- ltbodygt
16Result
17Style sheet
- Style sheets in CSS are made up of rules. Each
rule has three parts - the selector (in the example body), which
tells the browser which part of the document is
affected by the rule - the property (in the example, 'color' and
'background-color' are both properties), which
specifies what aspect of the layout is being set
- and the value ('purple' and 'd8da3d'), which
gives the value for the style property.
18Look at the example again
- ltstyle type"text/css"gt
- body
- color purple
- background-color d8da3d
- lt/stylegt
SELECTOR
value
property
19Style sheets
- Creating a style
- Applying styles in HTML files
20Style sheets
- Creating a style
- Applying styles in HTML files
21Creating a Style rule
- Step 1 Determine Selector (which identifies the
elements you wish to format). Put next to it - Example h1
- Step 2 Determine property value in which
property is the name of CSS property that applies
this format and value is one of valid options for
that property - Example colorred
- Step 3 Combine the results of step 1 and step 2
and put at the end. - If you have more than one property value pairs,
use semicolon () to separate them. - Example h1colorred
22Creating a selector
- The type or name of elements
- For instance body, paragraph
- The context in which the element is found
- For instance paragraphs in the middle of the
web page - The class or id of an element
- For instance the name of a paragraph in a web
page. -
23Examples
- For the type or name of elements
- h2 colorred
- h1 color purple
- The context in which the element is found
- divgaudi p colorred
- The class or id of an element
- divgaudi colorred
24DIV tag
- The ltdivgt tag defines logical divisions in a Web
page. - determines the alignment of that section of the
page. - defines the style of whole sections of HTML.
- names certain sections of your documents so that
you can affect them with style sheets or Dynamic
HTML - Syntax
- ltdiv alignltleftgtltcentergtltrightgtltjustifygt
- id namegt
- lt! this is a body of the div tag ?
- lt/divgt
25Example for DIV tag
- ltdiv id"gaudi" align"center"gt
- ltpgtMany tourists are drawn to Barcelona to see
Antoni Gaud's incredible architecture. lt/pgt - ltpgtBarcelona lta href"http//www.gaudi2002.bcn.es
/english/flash/home/GO.htm"gtcelebrateslt/agt the
150th anniversary of Gaud's birth in 2002.lt/pgt - lt/divgt
26Example for DIV tag
- Many tourists are drawn to Barcelona to see
Antoni Gaud's incredible architecture. - Barcelona celebrates the 150th anniversary of
Gaud's birth in 2002.
27Style sheets
- Creating a style
- Applying styles in HTML files
- Putting style sheet in HTML files
- Putting style sheet in a separate file
28Putting style sheet in HTML files
- ltstyle type"text/css"gt
- lt! This is where you put Style sheet information
? - lt/stylegt
29Example
- lthtmlgt ltheadgt
- lttitlegtAntoni Gaud - Introductionlt/titlegt
- ltstylegt
- h1 color purple
- lt/stylegt
- lt/headgt
- ltbodygt
- lth1gtAntoni Gaudlt/h1gt
-
- ltdiv id"gaudi" align"justify"gt
- ltpgtMany tourists are drawn to Barcelona to see
Antoni Gaud's incredible architecture. lt/pgt - lt/divgt
- lt/bodygt
- lt/htmlgt
Style sheet in HTML file
Style affects this h1 tag
30Result
31Putting the style sheet in a separate file
- Step 1 Open a new text file
- Step 2 Cut and paste the content inside ltstylegt
lt/stylegt tags (except the tag) - Step 3 Save in the same folder with HTML file
with the extension .css (e.g mystyle.css) - Step 4Replace ltstylegt and lt/stylegt tag with
- ltlink rel"stylesheet href"mystyle.css"gt
32Example
- lthtmlgt ltheadgt
- lttitlegtAntoni Gaud - Introductionlt/titlegt
- ltlink rel"stylesheet" type"text/css"
media"screen" href"descendant.css" /gt - lt/headgt
- ltbodygt
- lth1gtAntoni Gaudlt/h1gt
-
- ltdiv id"gaudi" align"justify"gt
- ltpgtMany tourists are drawn to Barcelona to see
Antoni Gaud's incredible architecture. lt/pgt - lt/divgt
- lt/bodygt
- lt/htmlgt
33Example of descendant.css
34Adding fonts
- body
- font-family Georgia, Times New Roman,
- Times, serif
- color purple
- background-color d8da3d
- h1
- font-family Helvetica, Geneva, Arial,
- SunSans-Regular, sans-serif
-
35Adding fonts
36More about fonts
- Font family
- font-family Georgia, Times New Roman, Times,
serif - Font size
- font-size20px
- Font type bold, italic
- font-style italic
- Font color
- colorcc00ff
37Example for font styles
- Choosing Font Family
- Choosing Italic
- Choosing Text color
38Practice
- 1. Cut and paste (or type) the following
codelthtmlgt ltheadgt - lttitlegt Styled Page lt/titlegt
- ltlink rel"stylesheet" type"text/css"
media"screen" hrefstyle.css" /gt - lt/headgt
- ltbodygt
- lt! Please insert your HTML code here --gt
- lt/bodygt
- lt/htmlgt
39Practice
- 2. Open a new file in TextPad and create style
sheet rules - - text color purple for the entire web page
- - background color d8da3d for entire web page
- - color red, font Times New Roman, size20px and
bold style for H1 tag - - font Arial, size 12px for normal paragraph
-
- Save this file as style.css (in the same
directory where you save your html file
40Practice
- Insert the HTML code so that it creates the
following web page -
The text doesnt have to be the same but you
should at least have a title and two paragraphs
41Style.css
- body
- color purple
- background-color d8da3d
- h1
- color red font-family Times New Roman
font-size 20px font-style bold - p
- font-family Arial font-size 12px
42Style.html
- lthtmlgt
- ltheadgt
- lttitlegtMy first web pagelt/titlegt
- ltlink rel"stylesheet" type"text/css"
media"screen" href"style.css"/gt - lt/headgt
- ltbodygt
- ltcentergt lth1gt Antoni Gaudí lt/h1gt lt/centergt
- ltpgt Gaudí's non-conformity, already visible in
his teenage years, coupled with his quiet but
firm devotion to the church, made a unique
foundation for his thoughts and ideas. - lt/bodygt
- lt/htmlgt
43Elements in HTML file
- Are like labels that identify and structure
different parts of a Web page - Example header, paragraph, division, table
- Elements can contain other elements
44Layout with style
- Block vs. Inline
- Box model
- Positioning a box
- Changing padding, border, margin, size, alignment
and color
45Block vs Inline
- An element of a web site can be block or inline
- If it is a block level, it will always be
displayed on a new line - Example
- ltpgt This element is at block level lt/pgt
- If it is an inline level, it will always be
displayed in the current line - ltpgt
- This is a ltemgt inline element lt/emgt
- lt/pgt
46Box model
- A web site can be treated as if every element is
contained in an invisible box - Content area
- Space surrounding that area (padding)
- Border
- Margin
- Four basic ways to position element box
- Static leave the box in the flow
- Absolute specify its exact coordinates with
respect to its parent (which is the element
contains the current element) - Fixed specify its exact coordinates with respect
to the browser windows - Relative move the box with respect to its
default position in the flow
47Changing from inline to block and vice versa
- Rule ltselectorgt displayblock
- Example navigation a displayblock
- Results
- Rule ltselectorgt displayinline
48Positioning Elements Absolutely
- Rule
- ltselectorgt positionabsolute topltvaluegt
left ltvaluegt bottomltvaluegt rightltvaluegt - ltvaluegt is the offset between this element and
its parent element - Example
49Affixing an element to the Browser Window
- Rule
- ltselectorgt positionfixed topltvaluegt
left ltvaluegt bottomltvaluegt rightltvaluegt - ltvaluegt is the distance between this element and
the edge of the browser windows - Example
- Note IE 6 does not support this
50Changing the Background
- Rule ltselectorgt background-colorltcolor value
or color namegt - Or
- ltselectorgt background-color transparent
- Example
51Changing the Foreground
- Rule ltselectorgt colorltcolor value or color
namegt - Or
- ltselectorgt background-color transparent
- Example
52Changing the Border
- Rule ltselectorgt
- border-stylelttypegt
- Border-width ltngt
- Border-color ltcolorgt
- Border-top ltvaluegt
- Border-rightltvaluegt
- Border-left ltvaluegt
- Border-bottom ltvaluegt
- type none, dotted, dashed, solid, double
- n desired width (E.g 4px)
- value width (e.g 2px)
- Example
53Changing the Margin
- Rule ltselectorgt
- margin x
- X desired space to be added expressed as a
length, or a percentage of the width of the
parent element or auto - Example
54Adding Padding around element
- Rule ltselectorgt
- padding x
- X desired space to be added expressed as a
length, or a percentage of the width of the
parent element - Example
55Example of HTML again
- lt!DOCTYPE html PUBLIC "-//W3C//DTD HTML
4.01//EN"gt - lthtmlgt ltheadgt lttitlegtMy first Web sitelt/titlegt
lt/headgt - ltbodygt
- lt!-- Site navigation menu --gt
- ltulgt
- ltligtlta href"index.html"gtHome pagelt/agt
- ltligtlta href"musings.html"gtMusingslt/agt
- ltligtlta href"town.html"gtMy townlt/agt
- ltligtlta href"links.html"gtLinkslt/agt
- lt/ulgt
- lt!-- Main content --gt
- lth1gtMy first styled pagelt/h1gt
- ltpgtWelcome to my first page!
- lt/bodygt
- lt/htmlgt
56Result
57Adding style for navigation bar (navigation.css)
- body
- color purple
- background-color d8da3d
-
- ul.navbar
- list-style-type none
- padding 0
- margin 0
- position absolute
- top 2em
- left 1em
- width 9em
Em equals to the elements font size. 2em
equals to twice the font size
58Adding style for navigation bar (navigation.css)
- ul.navbar li
- background white
- margin 0.5em 0
- padding 0.3em
- border-right 1em solid black
- ul.navbar a
- text-decoration none
- font-familyArial
- font-size18px
- alink
- color blue
- avisited
- color purple
59Using navigation bar
- lthtmlgt ltheadgt lttitlegtMy first Web sitelt/titlegt
- ltlink rel"stylesheet" type"text/css"
media"screen" href"navigation.css"/gt - lt/headgt
- ltbodygt
- lt!-- Site navigation menu --gt
- ltul class navbargt
- ltligtlta href"index.html"gtHome pagelt/agt
- ltligtlta href"musings.html"gtMusingslt/agt
- ltligtlta href"town.html"gtMy townlt/agt
- ltligtlta href"links.html"gtLinkslt/agt
- lt/ulgt
- lt!-- Main content --gt
- ltcentergt lth1gtMy first styled pagelt/h1gt lt/centergt
- lt/bodygt
- lt/htmlgt
60Results
61Practice
- 1. Cut and paste (or type) the following
codelthtmlgt ltheadgt - lttitlegt Styled Page lt/titlegt
- ltlink rel"stylesheet" type"text/css"
media"screen" hrefstyle.css" /gt - lt/headgt
- ltbodygt
- lt! Please insert your HTML code here --gt
- lt/bodygt
- lt/htmlgt
62Practice
- 2. Open a new file in TextPad and create style
sheet rules for - - text color purple for the entire web page and
background color d8da3d for entire web page - - unorderlist navbar with top2em, left4em,
width25em - - for items in unorderlistnavbar with white
background, border-right 1em solid black
display inline - - for links in navigation bar navbar font
Arial, size 18px, no text decoration - - color of a link in this web page blue
- - color of a visited link purple
- - h1 heading positionabsolute and left
alignment with top margin 2em - Save this file as style.css (in the same
directory where you save your html file - (Look at the css code that we have learned)
63Practice
- Insert the HTML code so that it creates the
following web page -
64CSS file (navigation.css)
- body
- color purple
- background-color d8da3d
-
- ul.navbar
- list-style-type none
- padding 0
- margin 0
- position absolute
- top 2em
- left 4em
- width 25em
-
65CSS file (navigation.css)
- ul.navbar li
- background white
- margin 0.5em 0
- padding 0.3em
- border-right 1em solid black
- display inline
-
- ul.navbar a
- text-decoration none
- font-familyArial
- font-size18px
-
- alink
- color blue
- avisited
- color purple
- h1
- positionabsolute
- text-alignleft
66HTML code
- lthtmlgt ltheadgt lttitlegtMy first Web sitelt/titlegt
- ltlink rel"stylesheet" type"text/css"
media"screen" href"navigation.css"/gt - lt/headgt
- ltbodygt
- lt!-- Site navigation menu --gt
- ltul class"navbar"gt
- ltligtlta href"index.html"gtHome lt/agt
- ltligtlta href"hobby.html"gtResumelt/agt
- ltligtlta href"hobby.html"gtHobbylt/agt
- ltligtlta href"links.html"gtLinkslt/agt
- lt/ulgt
- lt!-- Main content --gt
- lth1gtWelcome to my personal web pagelt/h1gt
- lt/bodygt
- lt/htmlgt
67Images
- Creating Web images
- Adobe Photoshop
- Photoshop Elements
- Paint Shop Pro
68Images on the Web
- Format
- Color
- Size and Resolution
- Speed
- Transparency
- Animation
69Format
- The format of an image on the Web should be
recognizable by Macs, Unix, Windows based OS - GIF (Graphic Interchange Format)
- widely supported image-storage format promoted
by CompuServe. Resolution is limited to 8-bits,
or 256 colors. - JPEG (Joint Photographic Experts Group )
- 24 bits. the compression scheme sacrifices some
image quality in exchange for a reduction in the
file's size. - PNG (Portable Network Graphics).
- A compressed image file format similar to JPEG
70Color
- 24 bits
- 16 bits
- 8 bits
- Browsers can mix two colors to produce the
missing color or can shift the missing color to
the one in the current set
71Other factors
- Size and resolution
- Images will be displayed depending on each
monitors resolution - Recommend to keep a page lt 600 pixels
- More pixels always translate to a bigger size
image - Speed
- Keep the size of an image smaller
- Compress the image
72Getting image
- Using search engines to find images
- Buy images on CD
- Buy a digital camera
73Using images
- Inserting images on a page
- ltimg srcfile name or URL widthx heighty
/gt - Example
- ltcentergt
- lth1gt Welcome to My Web sitelt/h1gt
- ltimg src"autumn.jpg" width "500" height"400"
/gt - ltpgt Autumn in Wisconsin lt/pgt lt/centergt
74Result
75Alternate Text
- If the images does not appear for some reasons,
the text will appear - Example
- ltimg src"autumn.jpg" width "500" height"400"
alt Picture of Foliage in Wisconsin/gt
76Result
77Specifying size for Speedier Viewing
- Find the size of an image
- Right click the image
- Choose Properties or Get Image Info
- Link a thumbnail to a larger image
- ltA HREF"autumn.jpg"gt
- ltimg src"autumn_little.jpg" alt "Picture of
Foliage in Wisconsin" /gt lt/agt - ltpgt Autumn in Wisconsin lt/pgt lt/centergt
78Result
79Result
80Making Images Float
- ltimg src"Castle.jpg" align"left" alt"Edinburgh
Castle in Scotland" width"500" height"480" /gt - ltpgt Edinburgh Castle in Scotland. Edinburgh
Castle dominates the city of Edinburgh like no
other castle in Scotland , and Edinburgh Castle
is unequalled in the whole of the British Isles .
Over one thousand years of history sit on top of
the famous Edinburgh rock and it is easy to see
why over a million visitors a year visit
Edinburgh Castle . - When you come and visit Edinburgh Castle you
will see why the early inhabitants of the area we
now call Edinburgh , made their first settlements
here, in what is now the city of Edinburgh .
People have always sought a safe refuge, and the
volcanic rock that forms the base of Edinburgh
Castle , has always afforded the ultimate safe
and defensive position in Edinburgh - lt/pgt
81Making Images Float
82Adding Space around an Image
- ltimg src"Castle.jpg" align"left" alt"Edinburgh
Castle in Scotland" width"500" height"480 - vspace32 hspace"20" /gt
83Adding Space around an Image
84Adding Horizontal Rules
- lthr size"10" width"80" align"center"
noshade"noshade" /gt
85Adding Horizontal Rules
86Practice
87Practice
- 1. Open TextPad, cut and paste (or type) the
following codelthtmlgt ltheadgt - lttitlegt Image page /titlegt
-
- lt/headgt
- ltbodygt
- lt! Please insert your HTML code here --gt
- lt/bodygt
- lt/htmlgt
- And save it as image.html
88Practice
- 2. Use Google (or any search engine that supports
image searching) at www.google.com. Click on
images. Type in the keywords of the image that
you are looking for. - 3. Modify the image.html file by adding html code
to display that picture and the description of
the picture.