程序代写代做 go javascript Java Excel C cache CGI graph html CS 200

CS 200
Lecture 05 TheWeb (HTML, CGIs, & CSS)
CS 200 Winter 2018 1 The Web
Abbreviations
aka Also Known As
CSS Cascading Style Sheets CWS Course Web Site
Reading
Miscellaneous Notes
The Non-Designer’s Design Book, by Robin Williams: • Chapters 1 – 6
• Pages 117 – 120 on Web Sites
Optional Background Reading
Learning Web Design (2/e, library reserve)
Extracts from HTML & XHTML (5/e) — The Definitive Guide, Chapter 8 on Cascading Style Sheets
 also available online from the University at http://safari.ora.com > MY BOOKSHELF – Book 27
Western Civilization’s tutorial on CSS properties (for reference)

http://www.westciv.com/style_master/academy/css_tutorial/introduction/css_intro.html
Sitepoint’s CSS Introduction and Documentation (for reference)

http://reference.sitepoint.com/css
The “Cascading Style Sheet Properties Quick Reference” (for reference)

in HTML & XHTML (5/e) The Definitive Guide, available online at http://proquest.safaribooksonline.com/ Book 27
CSS Pocket Reference (3/e), by Eric Meyer, O’Reilly & Associates (book store)
CS 200 Winter 2018 2 The Web

Administrivia
Please read and high-light, before lab:
• Assignment 5
• This week’s slides
There are hyper-text commented source files for many of the web pages used in this lecture
• Handouts / Commented HTML on the CWS
Major topics today
• read and recall pearl
• the client-server paradigm
• putting HTML in context
• relative vs absolute URLs
• tables as a layout tool
• forms
• styles in HTML (especially cascading style sheets – CSS)
Today’s lecture assumes an elementary understanding of HTML tags & attributes (eg. from CS 100)
• if you lack it, see Learning Web Design, or https://www.codecademy.com/courses/web-beginner-en- HZA3b/0/1
CS 200 Winter 2018 3 The Web
New applications for this week
• TextWrangler
a text editor
• EditiX
a cross-platform XML editor
• StyleMaster
a cross-platform CSS editor
Road Map
• You can use any text editor you’d like, though some are nicer than others for various reasons
This week’s lecture builds on the preceding weeks’ material:
• tables
• styles
• graphics
CS 200 Winter 2018 4 The Web

Dialogs and Menus
• Menus
• Dialogs
• Toolbars & Palettes
Documentation
• The user manual
• Online help
• Online tutorials
The Read ‘n Recall Pearl
CS 200 Winter 2018 5
The Web
You have an understanding of:
• Tables
• Styles
• Indirection
CS 200 Winter 2018 6
The Web
Assumptions

Things to Think About
• How does the manipulation of data objects differ from other applications?
• Is there more than one way to manipulate a data object?
CS 200 Winter 2018 7 The Web
Client-Server File Sharing
EG the AppleShare file Server on a local Mac Server
• your lab Mac is the “client”: slower, cheaper, smaller disks
• student.cs is the “server machine”: faster, more expensive, bigger disks
• AppleShare is the “server application,” running on the server machine
• “share points” are folders on the server that are made available over the network
• “network disks”
• “mounting” a share point (use the Finder’s Go > Connect to Server… menu item)

creates a “network disk” on your client machine
• an icon appears on the desktop, just as for a local disk
• use a network disk just like a local disk, although it’s a bit slower
• “network folders”
• these are subfolders (aka subdirectories) of a network disk
• unlike the other terms on this slide, “network folder” is a CS200-invented term As distinct from “peer-to-peer” file sharing
CS 200 Winter 2018 8 The Web

The Web (like file-sharing) has a client-server model
Many of the machines on the Internet are “web servers”
• any machine (“client”) on the web can ask them for data
• actually, they’re asking a particular application
 running on that machine for data

(which is identified by a “port”)
The client uses a “browser” to request & display web pages
• eg. Firefox, Safari, Chrome, Explorer, Opera, …
• browsers decide how to render the HTML, based on • HTML tags found in the document
• what kind of display is available
• user preferences
200 request .html
Exp .html
Schedule .html
oscar.cs.uwaterloo.ca (Server)
Web Server
Lab Macintoshes (Clients)
• browsers are often (but not always) consistent in how they do this
•• •
For security
• a web server can only return files in the “server subtree”
• sometimes that’s rooted in the folder holding the server app
• usually this “web root folder” can be set
 when the web server is started
CS 200 Winter 2018 9
The default Mac OS X web server application (Apache) is at /usr/sbin/httpd;
the default web document root folder is at /Library/ WebServer/Documents/.
The Web
The files returned can be
• web pages
• pictures
• other stuff…
Data Returned By Web Servers
A “web page” is a TEXT file containing
• text to be displayed (text “elements”)
• “tags”
• eg and

that control presentation of the text—they’re really styles • “links” containing “URLs” (eg and )
• to other web pages
• to graphics, for display on the page
• to sounds, to be played when the page is viewed
• etc—add post-install “plugins” to handle new file types
 (/Library/Internet Plug-Ins/ or ~/Library/Internet Plug-Ins/ on Macs)
• URL = Uniform Resource Locator (eg “www.student.cs.uwaterloo.ca/~cs200/index.html”)
 (aka URI = Uniform Resource Indicator—yuck)
CS 200 Winter 2018 10 The Web

Formatting Tags in WordPerfect
What you see here are “property tags” 

but they could equally well be (named) style tags
Strip out all the formatting codes
 to get a “text” or “ascii” file
CS 200 Winter 2018 11 The Web
T
The HTML for this web page
Yuck!
Recall that browsers ignore
• multiple blanks
• carriage returns
• blank lines
A Toy Web Page
Jen’s Fake Home Page

Welcome to my Web page

Warning! This is not my real home page. It’s just a little something I made up for the occasion. But just in case you’re interested, I’ll tell you a bit about me.


Places I’ve Lived

  • 
 Akron, OH
  • Hudson, OH
  • Sourth Bend, IN
  • Boston, MA

(Adapted from “Designing for the Web – Getting Started in a New Medium” by Jennifer Niederst and Edie Freedman.)


Use these to make your HTML more readable!
• You’ll lose marks in CS 200 if you don’t
• You’ll make your life difficult if you don’t
• It will be very difficult for anyone else to read and use your code if you don’t
CS 200 Winter 2018 12
The Web

The HTML for our Toy Web Page, Readably Formatted

Jen’s Fake Home Page


Welcome to my Web page




Warning! This is not my real home page. It’s just a little something I made up for the occasion.
But just in case you’re interested, I’ll tell you a bit about me.




Places I’ve Lived



  • Akron, OH
  • Hudson, OH
  • South Bend, IN
  • Boston, MA



(Adapted from “Designing for the Web – Getting Started in a New Medium”
by Jennifer Niederst and Edie Freedman.)




CS 200 Winter 2018 13 The Web
HTML is stored in “[ASCII] text files”
HTML tags as (named) styles
Safari 9.1.1
Chrome 54
Firefox 48.0.1
• whose definitions are supplied by the browser
• same web page, different browser,

generally similar (but not identical) appearance…
Always use closing tags (eg

, )
• otherwise the browser must guess their location
• be prepared for XHTML, XML & CSS

• does not mean “header”
• … contain information about the page
• eg.
• eg.
• eg.
… shows up in most browsers’ title bar browsers use … to label bookmarks
index engines give words in … extra weight
… contain info displayed in the page
Discussion Points
CS 200 Winter 2018 14
The Web

More Discussion Points
Browsers also ignore tags they don’t recognize
• eg. tags you misspell
• this is actually a feature
• so newly invented tags don’t screw up old browsers
• so IE-specific tags don’t screw up Chrome, & vice-versa • etc
• but it makes debugging HTML harder
• therefore… when a tag doesn’t seem to have any effect
• suspect misspelling
• Validation – see the assignment for details
• that’s what the magic incantation is for (see next slide)
Upper case vs lower case
• who cares?
• HTML is case-insensitive: works fine • XHTML requires that tags be lower case
• XML is case-sensitive
• suggestion: use lower case
CS 200 Winter 2018 15 The Web
A Simple HTML Table




Mark Report


Top CS200 Marks











ID Number Final Grade
94010203 81%
98102030 75%
96000123 67%




CS 200 Winter 2018
16
The Web
For a list of valid doctypes, see http://www.w3.org/QA/2002/04/valid-dtd-list.html

. . .

surround the entire table

. . .

surround a table row

. . .

surround a table (cell) definition
By default
a table and its cells are as wide as they need to be
For details, see
• HTML The Definitive Guide (library reserve) • PageSpinner Help
Tables as a (deprecated) all-purpose layout tool in HTML
• (Hmm. Are tables a useful layout tool in word processors?)
HTML Tables can be nested

and HTML cells can be “merged” • horizontally (colspan=”n”)

and/or
• vertically (rowspan=”n”)
• no L-shaped regions, however
CS 200 Winter 2018 17
The Web
HTML Table Tags
Mark Twain
Samuel Langhorne Clemens (November 30, 1835 – April 21, 1910), better known by his pen name Mark Twain, was an American humorist, satirist, novelist, writer, and lecturer.
Although Twain was confounded by financial and business affairs, his humor and wit were keen, and he enjoyed immense public popularity. At his peak, he was probably the most popular American celebrity of his time. In 1907, crowds at the Jamestown Exposition thronged just to get a glimpse of him. He had dozens of famous friends, including William Dean Howells, Booker T. Washington, Nikola Tesla, Helen Keller, and Henry Huttleston Rogers. Fellow American author William Faulkner is credited with writing that Twain was “the first truly American writer, and all of us since are his heirs.” Twain died in 1910 and is buried in Elmira, New York.
Pen Names
Clemens maintained that his primary pen name, “Mark Twain,” came from his years working on Mississippi riverboats, where two fathoms (12 feet, approximately 3.7 meters) or “safe water” was measured on the sounding line. The riverboatman’s cry was “mark twain” or, more fully, “by the mark twain” (“twain” is an archaic term for two). “By the mark twain” meant “according to the mark [on the line], [the depth is] two fathoms”. Clemens provides a footnote to Chapter 8 (“Perplexing Lessons”) of Life on the Mississippi where he explains “mark
Previewing your Webpage
• Save your work in the text editor
• Open the same file up in a web browser
• Every time you save the text file, refresh the webpage • For example…
Text Wrangler Chrome
• Some text editors or in browser text editors allow you to preview your page within the app
• It’s recommended to also preview it in common web browsers to make sure it works where others will see it
CS 200 Winter 2018 18 The Web

Chrome’s Inspect
Most browsers allow you to view the page source, which will help you with debugging your own webpages.
CS 200 Winter 2018 19 The Web
Safari’s > Show Inspector
CS 200 Winter 2018 20 The Web

URLs — Uniform Resource Locators
For
search , 

(equivalent to search )
• http is the “protocol”
• jcbServer is the server’s “local name”
• cs.uwaterloo.ca is the “domain” in which the server is located
• jcbServer.cs.uwaterloo.ca is the server’s “host domain name”
• 80 is the “port” on which jcbServer’s web server application is listening
• /cs200/search/search.html is the “absolute path” from the server’s web root folder to the file
CS 200 Winter 2018 21
The Web
Another example:
Another Example URL
John C Beatty
fragments/bio/biography.html
• is a “relative path” to the target file
• starting in the folder containing the page holding the link
• (note the LACK of an initial “/” and host domain name)
works the same way
CS 200 Winter 2018 22 The Web

Relative vs. Absolute Paths (1)
The web root folder
• a web server can only return files in the “server subtree”
• sometimes that’s rooted in the folder holding the server app
• sometimes this “web root folder” can be set elsewhere
W ebRoot
1st Year 2nd Year
• • •
1st Year
CS100 CS120 CS134
2nd Year
CS200 CS212 CS230
•• •• ••
CS120
CS100
CS200
CS200.html hBook.html hPage.html
• • •
CS 200 Winter 2018
23
The Web
CS120.html CS100.html
• •
• • •
A link in CS100.html to CS200.html could be written as
CS200
• Note the initial slash
• This is an “absolute path”
• The host domain name is implicit
W ebRoot
1st Year 2nd Year
• •
Relative vs. Absolute Paths (2)
1st Year
2nd Year
CS200 CS212 CS230
• ie the same as the referencing web page
Or as
CS100 CS120 CS134
CS200
• Note the initial “••/••/”
• This is a “relative path”
• / means “go up one level to the parent folder”
CS120
• ••
CS100 CS200

• •
•• • •
• ••/••/ means “go up two levels,” etc
• note: for security reasons, the web server application will

prevent the path from rising above the web root folder!
• Note that cs200/cs200.html is also a relative path Or using an explicit host domain name

AND an absolute path
CS200
It makes no sense to combine a host domain name and a relative path
 —what folder would the path be relative to?
• •
CS 200 Winter 2018 24 The Web
CS100.html CS120.html •
••
CS200.html hBook.html hPage.html

When to use relative vs. absolute paths
Absolute paths
• always start at the web root folder
• are necessary between machines
• if a host domain name is present, the path is necessarily absolute
Relative paths
• start at the document containing the link
• make it MUCH easier to move web pages around as a group
eg. if all the cs200 pages use relative URLs amongst themselves

then I can move the cs200 subtree somewhere else (like to another server)
 without breaking the links between the cs200 pages
• but if a file in the group links to a file on the same machine not in the group

it must use an absolute file path (or the group can’t be moved w/o breaking that link)
IMPORTANT
• you MUST write “%20” instead of a space in URLs
• and look out for trailing blanks
So within a web site…
• use a relative path when the two files are more likely to be moved together (eg. a page & an image in it)
• use an absolute path when the two files are more likely to be moved separately
CS 200 Winter 2018 25 The Web
An HTML form is a web page

with “[interface] widgets” for supplying data:
• text edit boxes
• check boxes
• radio buttons
• pop-up menus
Forms
CS 200 Winter 2018 26
The Web

Web Servers can’t know in advance:
• what data will be sent to them from forms
• what should be done with it
So there’s a convention (the “Common Gateway Interface”):
Forms and CGIs
mac6001 (Client)
Safari
• for identifying the particular application
• to which form data should be sent for processing
Actually, the CGI scheme is more general than this:
• a web server can run any application
 and return its output
When the submit button is pressed
• the data is sent to a web server
• the web server forwards the data

to a “cgi” (a separate program)
• the cgi processes the data &

returns a web page to the server
• the server passes that response
 on to the browser
Plug-ins
CS 200 Winter 2018 27
network connection
A Lab Macintosh
jcbServer (Server)
ReportMarks.cgi
University4
Students Register Assignments Marks
Root .html
Implementation .html
ï ï ï
Apache — the web server app
Sybase
File Maker
The Web

The CS 200 Request Marks Form (simplified)
T
Request Your Marks in CS 200

To retrieve your marks to date in CS 200, please enter your last name (case doesn’t matter) and student ID in the boxes shown below.


Then click on the Fetch Marks button – ordinarily it shouldn’t take more than thirty seconds or so for your marks to come back. (Please be patient – I’m only a Mac IIfx!)


If you find a discrepancy, please notify the course tutor as soon as possible.



Your Last Name:



Your ID Number:





Note the use of a “hidden parameter” that the user never sees so that forms for different courses can use the same cgi.
CS 200 Winter 2018 28 The Web

What Gets Sent to the Server (GET)
T
GET ../ReportMarks.cgi?course=cs200&surname=Daly&idnumber=00000000 HTTP/1.0 Connection: Keep-Alive
User-Agent: Mozilla/4.06 (Macintosh; U; PPC, Nav)
Host: jcbServer.cs.uwaterloo.ca
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
Accept-Encoding: gzip Accept-Language: en Accept-Charset: iso-8859-1,*,utf-8
What comes back
../ReportMarks.cgi locates the program (a “cgi”) to which the server forwards the form’s data Notice
• that the URL from which a web page came always appears in the location bar • that the forms data is encoded in the URL
• how that URL appears in what’s sent to the server
• why the path to the cgi had better not contain a question mark!
CS 200 Winter 2018 29 The Web
The rules for this stuff are part of the
“http protocol.”
The request marks form could have said

In which case the forms data would be transferred a bit differently
POST Actions
POST ../ReportMarks.cgi HTTP/1.0
Connection: Keep-Alive
User-Agent: Mozilla/4.06 (Macintosh; U; PPC, Nav)
Host: 192.168.1.100
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, image/png, */*
Accept-Encoding: gzip
Accept-Language: en
Accept-Charset: iso-8859-1,*,utf-8
Content-type: application/x-www-form-urlencoded
CONTENT-LENGTH: 43 course=cs200&surname=Daly&idnumber=00000000
The details of the difference between POST and GET are not important to us But you do need to know that:
• POST is necessary for large quantities of data
 — say > 256 characters
• POST’ed form data does not appear in the URL 
 and therefore cannot be bookmarked
CS 200 Winter 2018 30
The Web

Laying Out a Form as a Table — The Form


Request Your Marks in CS 200


(case doesn’t matter) and student id in the boxes shown below.



Then click on the Search button – ordinarily it shouldn’t
take more than thirty seconds or so for your marks to come back.
(Please be patient – I’m only a Mac IIfx!)


If you find a discrepancy, please notify the course tutor as soon as possible.



CS 200 Winter 2018 31 The Web
To retrieve your marks to date in CS 200, please enter your last name















Your Last Name:
Your ID Number:

Which:
Assignments
Midterm
Final
Course Mark





CS 200 Winter 2018
32 The Web
formtags tabletags

Styles in HTML
Most tags are named styles: , ,

,

    , …
    • these are “logical tags”
    • browsers decide how to render them
    Although a few are not: ,
    • these are “physical tags”
    • browsers have no choice
    Generally speaking
    • the browser, not the web author, controls layout
    • browsers sometimes behave differently
    But appearance is important!
    CS 200 Winter 2018 33
    The Web
    The response
    Controlling HTML Layout
    • abusing tables and frames
    • new tags and attributes
    • proprietary tags and attributes
    • postscript and pdf (Adobe’s “Portable Document Format”) via “plugins”
    Wouldn’t it be nice …
    • if HTML had USER-DEFINED [named] styles?
    • like those we find in word processors?
    • that authors could use to control layout?
    CS 200 Winter 2018 34 The Web

    Cascading Style Sheets
    Style definitions may appear at the beginning of a web page There are five style definitions in this example
    • the first specifies the default font to be used
    • the second and third attach default “properties” (ie attributes) to and

    • the last two define property bundles that can be applied to

    , by using classes


    These are called “selectors”



    }
    }
    } }

    This paragraph will be centered.

    This paragraph will be centered and bold.


    This paragraph will be centered and italic.


    This word will be green.




    CS 200 Winter 2018 35


    The Web
    External CSS files
    Or … style definitions may be EXTERNAL to a web page
    • so that multiple web pages can use them
    • much more important for HTML than for word processing
    • An example style sheet file
 named simple.css
    • An example html file
 that uses simple.css
    Notice that all four paragraphs are centered and in Myriad Pro
    • The contents of

    and

    “inherit” the properties of

    ,
 so they don’t have to explicitly set them
    • Inner elements inherit properties from outer elements containing them (when that makes sense)
 — eg the

    inherit Myriad Pro from the … in which they appear
    BODY { FONT-FAMILY: ‘Myriad Pro’, sans-serif }
    SPAN { COLOR: green }
    P { TEXT-ALIGN: center }
    P.A { FONT-WEIGHT: bold }
    P.B { FONT-STYLE: italic }





    This paragraph will be centered.


    This paragraph will be centered and bold.


    This paragraph will be centered and italic.


    This word will be green.




    CS 200 Winter 2018 36 The Web

    A Larger Example – Task B from the Winter 98 Lab Exam
    T
    CS 200 Winter 2018 37 The Web
    LabExam.css
    Note the period that begins each style name
    •Block {
    font-family: “Palatino, serif”;
    line-height: 15px; margin-top: 7px;
    font-family: “Palatino, serif”; line-height: 15px;
    margin-top: 5px;
    margin-left: 25px;
    }
    •Item2 {
    }
    •}
    these are called classes
    • such styles can be used in any tag (if they make sense…)

    is (effectively) a replacement for


    •Item1 {
    • with no default properties
    • (some properties of built-in tags like

    can’t be over-ridden) [still?]
    font-family: “Palatino, serif”; margin-top: 5px;

    and

    are examples of “block level tags” or elements
 (ie. they cause a line break)
    is an “inline level tag” (aka an “inline element”)
    • with no built-in properties
    • does not cause a line break
    , , and are other examples
    “STYLE” is used to set CSS attributes for a particular tag only
    • eg.

    blah, blah, blah…

    • eg.

    good stuff

    • eg.

  1. clear desk
  2. • eg. Good work!
    Block level tags generate automatic line breaks before & after.
 Inline tags do not; one can follow another on the same line.
    CS 200 Winter 2018 38
    •Footnote {font-family: “Palatino, serif”; font-size: 10pt;
    line-height: 13px; margin-top: 5px;
    }
    •Emphasize {
    }
    •Shout {
    }
    font-style: italic;
    font-weight: bold;
    The Web

    TaskB.html — the “body” part of the web page (1)
    T



    Lab Exam – Task B



    Sample Lab Examp – Task B


    This page is best displayed with • • •


    To use computers effectively it is important
    •••



    The problem.
    As a teacher, you often want • • •


    The solution.
    You have a FileMaker table • • •

    CS 200 Winter 2018 39
    The Web
    TaskB.html — the “body” part of the web page (2)


    Password-protected demonstration solutions • • •


    Demo Course Grades.
    When the Do It! button on the Choose layout • • •


    Demo Make Histograms.
    Click the Get Data button in any • • •


    The charts in By 5 and By 10 can • • •


    You are to duplicate the behaviour • • •


    (The relative weight of important pieces • • •
    •••
    CS 200 Winter 2018 40 The Web

    Another Example, from “Eric Meyer on CSS”
    http://jcbserver.uwaterloo.ca/cs200/ericMeyer/ericMeyer.html
    CS 200 Winter 2018 41 The Web
    T
    body {
    background:
    The Style Sheet
    rgb(153,102,51);
    black;
    font-family: ‘Myriad Pro’, sans-serif;
    div#p2 {
    margin:
    }
    div#menu {
    float:
    width:
    padding:
    margin:
    border:
    background:
    }
    div#menu a {
    display:
    text-align:
    padding:
    0 10em 0 2em;
    right;
    5em;
    0;
    0 -1.5em 0.25em 0.5em;
    3px solid rgb(50,50,175);
    white;
    block;
    center;
    0.2em 0.5em 0.2em 0.5em;
    0 11em 0 2em;
    0.2em 0 0.5em 0;
    center;
    color:
    }
    div•wrap { background:
    color:
    margin: }
    p{
    rgb(251,233,198);
    rgb(122,74,26);
    0 2em;
    0;
    0.25em 1em 0.25em 1em;
    1.25em;
    120%;
    margin:
    padding:
    text-indent:
    line-height:
    0 ≤ r, g, b ≤ 255
    }}
    h1, h2 {
    margin:
    padding: }
    div#p1 {
    margin:
    }
    0;
    0.25em 0.5em 0.25em 0.5em;
    0 2em 0 10em;
    div#footer {
    margin:
    }
    padding:
    text-align:
    font-style: italic;
    color:
    rgb(128,128,128);
    CSS for

    a colour name
    top, right, bottom, left
    top, right, bottom, left
    CS 200 Winter 2018
    42
    TheWeb

    What we’ve seen
    p { • • • } p.name
    p#name
    sets attributes for all

    tags
    sets attributes for all

    tags sets attributes for the only

    tag
    There are a variety of useful selectors we haven’t discussed, including
    h1, h2, h3 { • • • }
    p[title] { • • • } p[title=”important”] { • • • } h1 > strong { • • • }
    h1 + p { • • • }
    tr > td:first-child
    grouped selectors (same attributes for multiple tags)
    attributes for all tags

    (ie

    tags having a title attribute)
    attributes for all tags

    attributes for appearing “immediately” within an

    
 eg

    This is very important.

    attributes for any

    that immediately follows an


    eg

    Section A

    For this para.

    But not this one.

    attributes for

    when it is the first child of a


    eg

    matches this but not this

    Other Selectors
    and various combinations of these.
    Effectively, they do “pattern matching.”
    See Chapter 2 of “CSS The Definitive Guide” if you’re curious.
    (You’re not expected to memorize these for CS 200—this is useful “read and recall [someday] info”)
    CS 200 Winter 2018 43 The Web


    A Simple Eric Meyer • • •


    much room to think

    Sometimes I find myself • • •

    I suppose it’s the taste • • •

    a fun guy

    Good evening, my name is Rootsy • • •



    The HTML
    CS 200 Winter 2018 44
    The Web
    Notice that attributes can come
 from more than one style definition
    • egfromdiv.wrap{…}anddiv#p1{…},
 applied to

    • whenthathappens,they’remerged
    • ifthere’saconflict,“themorespecific
    wins”
    eg p1 over wrap because
 only one tag can have id=p1

    Classes vs. IDs
    Classes
    • can be used any number of times
    • defined like:
    .red {
    color: red;
    }
    • the . indicates that it’s a class
    • this can now be applied to other styles
    • eg.

    will have all the attributes from

    and all the attributes from .red
    • If you want a class that can ONLY be applied to the

    tag (and not to any other tags), defined it like:
    p.red {
    color: red;
    }
    • You can still use

    with the same results as before, but

    has no meaning
    IDs
    • should only be used once (for use with JavaScript – you don’t need to know why)
    • defined like:
    #red {
    color: red;
    }
    • this can now be applied to other styles
    • eg.

    will have all the attributes from

    and all the attributes from #red
    So what should you use?
    • there are reasons to use both classes and IDs
    CS 200 Winter 2018 45 The Web
    Discussion
    The “class” attribute can be used by many tags, which share its meaning

    The “id” attribute is supposed to uniquely identify a tag (ie only be used once)
 Both specify a style to use on their content
    Style sheets can come from
    • the web page author
    • the user, who can often specify a style sheet in the browser’s preferences
    • the browser (ie. built-in)
    — And this is their order of priority (from high to low) when a conflict arises for a particular attribute
    Browsers are finicky about CSS syntax
    • if your CSS seems to have no effect, check for syntax errors / use a CSS validator
    The detailed rules for resolving conflicts are (considerably) more complicated;
    • see Section 8.1.9 of “HTML & XHTML – The Definitive Guide,” 5/e, for a fuller explanation
    • or Chapter 3, “Structure and the Cascade,” in Cascading Style Sheets – The Definitive Guide for details — but you shouldn’t need to
    Note: there’s a lot more to CSS than we’ve had time to talk about
    CS 200 Winter 2018 46 The Web

    For More (Optional) Information on CSS
    Western Civilization’s
    • “Complete CSS Guide” at
 http://www.westciv.com/style_master/academy/css_tutorial/introduction/css_intro.html
    • “Properties Introduction” (the Complete CSS Guide’s section on CSS attributes) at
 http://www.westciv.com/style_master/academy/css_tutorial/properties/index.html
    HTML & XHTML — The Definitive Guide, 5/e, by Musciano & Kennedy, Chapter 9, “Cascading Style Sheets”
    • on reserve in the library (an earlier edition, without “XHTML” in the title
    • or at http://safari.ora.com > MY BOOKSHELF – Book 26 from a University computer

    Chapter 8 “Cascading Style Sheets” & the appendix “Cascading Style Sheet Properties Quick Reference”
    • (the 6th edition was published in October of 2006)
    Cascading Style Sheets — The Definitive Guide, by Eric Meyer
    • 3rd edition, © 2006, O’Reilly & Associates, 0-596-52733-0.
    • or the 2/e at http://www.safari.ora.com > MY BOOKSHELF – Book 9 from a University computer
    Typetester: a neat web page (w/Javascript+CSS) for comparing various fonts side-by-side in your browser
    • typetester.maratz.com
    XyleScope: a neat tool for dissecting the CSS in pages you encounter on the web ($20, Mac only) • www.culturedCode.com/xyle/
    CS 200 Winter 2018 47 The Web
    TypeTester: typetester.maratz.com
    T
    CS 200 Winter 2018 48 The Web

    Common Sources of Confusion in the Lab
    You can use Firefox or Safari’s File > Open File… menu item
    • that’s effectively what PageSpinner’s Preview button / menu item does
    • HOWEVER
    File > Open File… is not as fussy about paths as most web servers
    – it won’t complain about spaces in URLs
    – it won’t complain about trailing blanks in file names
    • So you MUST also ask student.cs.uwaterloo.ca web server to access your web pages 
 to be certain that the URLs in them work
    www.student.cs.uwaterloo.ca/YourUsername/root.html
    Browsers “cache” (most) pages you have browsed on your local disk
    • When you’ve changed the contents of a page and saved it to your network disk from PageSpinner,

    option-click the Reload button or And a word of advice … use
    • closing tags (eg ,

    )
    • indentation
    • blank lines
    to structure your HTML

    — it makes debugging much easier
    CS 200 Winter 2018
    to ensure your browser REALLY gets the new version
    49 The Web
    Finally…
    Remember that does NOT mean

    • …
    • enclose information ABOUT the web page • that is not displayed IN the page

    illustrates this better than Most browsers have a “View > Source…” menu item

    that will show you the HTML source for the page currently being displayed Warning
    • CSS is still not perfectly implemented by contemporary browsers,
 although the situation is much better now than it was a few years ago
    • So use the latest release of whatever browser you like
 when experimenting with Cascading Style Sheets
    • Also, StyleMaster has lots of info about browser quirks & bugs
    CS 200 Winter 2018 50 The Web




    X O

    O

    O X


    This text is centered WITHIN
    the space occupied by the <example> … </example> block.

    CS 200 Winter 2018 51
    The Web
    XML
    doc { font-family: font-size:
    } xmlTable {
    display:
    “Comic Sans MS”, sans-serif; 20pt;
    table;
    color:
    background-color: yellow;
    black; margin-top:
    Use LR margins of auto
 to center a block-level
 element within its parent.
    Use text-align: center
 to center text within
 an element.
    52 The Web
    margin-left: margin-right:
    }
    row {
    display:
    }
    cell {
    display:
    1em; auto;
    auto; table-row;
    table-cell;
    ToyTable.css
    padding-right: 0.2em; padding-left: 0.2em; padding-top: 0.2em; padding-bottom: 0.2em;
    width: text-align:
    } example {
    display:
    padding: background-color: cyan;
    margin-left: margin-right: text-align:
    }
    CS 200 Winter 2018
    0%; 50%;
    center;
    1.5em; center;
    block;




    X O

    O

    O X



    This text is centered WITHIN
    the space occupied by the <example> … </example> block.

    0.5em;

    XML—w/o the



    X O

    O

    O X


    This text is centered WITHIN
    the space occupied by the <example> … </example> block.

    CS 200 Winter 2018 53
    The Web
    CSS + JavaScript To Change The Default Font
    Example: changing the font locally
    S?
    • local:
    • remote:
    http://127.0.0.1/cs200/switchingFontsWithJavascript/JensHomePage.html http://jcbserver.cs.uwaterloo.ca/cs200/switchingFontsWithJavascript/JensHomePage.html
    CS 200 Winter 2018 54 The Web

    The Javascript for this Example
    S?


    Jen’s Fake Home Page

    •••

    Choose A Font


    Arial

    Palatino

    Comic Sans MS



    CS 200 Winter 2018
    Think about Excel scripting as you read this 55 JavaScript. The Web
    CSS + JavaScript To Switch Style Sheets
    Example: switching style sheets dynamically
    • local: http://127.0.0.1/cs200/switchingStyleSheets/JensHomePage.html
    • remote: http://jcbserver.cs.uwaterloo.ca/cs200/switchingStyleSheets/JensHomePage.html
    S?
    See JensHomePage.html and the javascript source file global.js in …/cs200/switchingStyeSheets/ for details if you’re curious.
    (Note that the color of the “Warning!” paragraph is chosen randomly.)
    CS 200 Winter 2018 56 The Web

    CSS + JavaScript
    Adding a little JavaScript to CSS (of the sort covered in CS 100)
    • dynamically changing CSS attributes
    • collapsing menus
    • absolute positioning of layers (remember Photoshop & Illustrator?)
    • and much, much more
    Example:
    • local: http://127.0.0.1/dynamicMenus.html
    • remote: http://jcbServer.cs.uwaterloo.ca/cs200/ericMeyer/dynamicMenus.html
    CS 200 Winter 2018 57
    The Web


    An Illustration of Dynamic Fonts & Menus

    absolute;
    2.5in;
    0.5in;
    CS 200 Winter 2018
    58 The Web
    text-align:
    center;
    The CSS for this Example
    S?
    position:
    left:
    top:
    background-color: #FFFF00;
    padding:
    25px;
    sans-serif; }
    none; none;
    } }
    15pt; bold;

    The Content for this Example
    S?

    An Illustration of Dynamic Fonts & Menus

    Larger Title

    Smaller Title

    UofW (+/-)