Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
25 views

Module 1

htmlcss

Uploaded by

gkfgvk13412
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

Module 1

htmlcss

Uploaded by

gkfgvk13412
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 72

Internet and Web Programming

MODULE – 1
Fundamentals of Web, XHTML, CSS
A Brief Introduction to the Internet
Internet History

• 1960’s: U.S. Department of Defense (DoD)


❑ interest in developing large scale network
❑ purpose communication, program sharing and remote computer access

• ARPAnet - late 1960s and early 1970s


❑ For ARPA-funded research organizations

• BITnet, CSnet - late 1970s & early 1980s for email and file transfer for other institutions

• NSFnet - 1986
❑Originally for non-Department of Defense funded places
❑Initially connected five supercomputer centers
❑By 1990, it had replaced ARPAnet for non-military uses
❑Soon became the network for all (by the early 1990s)
NSFnet eventually became known as the Internet
Internet History
What the Internet is:
“Collection of computers connected in communication network”
Or
“Its a global computer network that provides variety of information and communication facilities, consisting
of interconnected networks using standardized communication protocols.”

• A world-wide network of computer networks


• At the lowest level, since 1982, all connections use TCP/IP
• TCP/IP hides the differences among devices connected to the Internet
Internet Protocols

• Internet Protocol (IP) Addresses


• Every node has a unique numeric address
• Form: 32-bit number (its 4, 8bit number separated by periods)
• these 4 parts helps to decide where the message is intended to reach and been used by Internet
routing computers.
• New standard, IPv6, has 128 bits (1998)
• Organizations are assigned groups of IPs for their computers based on organization type
ex: large organizations may be assigned 16million ip’s (12.2.2.2)

• Problem: By the mid-1980s, several different protocols had been invented and were
being used on the Internet, all with different user interfaces (Telnet, FTP, Usenet, mailto)
Domain names
“A domain name is your website name. A domain name is the address where Internet users can
access your website. A domain name is used for finding and identifying computers on the
Internet. computers use IP addresses, which are a series of number.”
• Form: host-name.domain-names
• DNS servers - convert fully qualified domain names to Ips
• All the requests from the browsers are routed to name server, name server
plays vital role in handling queries regarding the location of a domain name's
various services.
Client and Server

• Clients and Servers are programs that communicate with each other
over the Internet
• A Server runs continuously, waiting to be contacted by a Client
• Each Server provides certain services
• Services include providing web pages
• A Client will send a message to a Server requesting the service
provided by that server
• The client will usually provide some information, parameters, with the
request
The World-Wide Web

• A possible solution to the proliferation of different protocols being used on


the Internet
• Origins
• Tim Berners-Lee at CERN proposed the Web in 1989
• Purpose: to allow scientists to have access to many databases of scientific work through their
own computers
• Document form: hypertext
• Pages? Documents? Resources?
• We’ll call them documents
• Hypermedia – more than just text – images, sound, etc.

• The WWW/Web uses protocols http, that runs on the Internet


• there are several others (telnet, mailto, etc.)
Web Browsers

• Browsers are clients - always initiate, servers react (although


sometimes servers require responses)
• Mosaic - NCSA (Univ. of Illinois), in early 1993
• First to use a GUI, led to explosion of Web use
• Initially for X-Windows, under UNIX, but was ported to other platforms by late
1993
• Most requests are for existing documents, using HyperText Transfer
Protocol (HTTP)
• But some requests are for program execution, with the output being returned
as a document
Web Servers

• Provide responses to browser requests, either existing documents or


dynamically built documents
• Browser-server connection is now maintained through more than one
request-response cycle
• All communications between browsers and servers use Hypertext
Transfer Protocol (HTTP)
• Web servers run as background processes in the operating system
– Monitor a communications port on the host, accepting HTTP messages when
they appear
URLs

• General form:
scheme:object-address
• The scheme is often a communications protocol, such as telnet or ftp
• For the http protocol, the object-address is: fully qualified domain name/doc path
• For the file protocol, only the doc path is needed
• Host name may include a port number, as in zeppo:80 (80 is the default, so this is silly)
• URLs cannot include spaces or any of a collection of other special characters (semicolons, colons,
...)
• The doc path may be abbreviated as a partial path
• The rest is furnished by the server configuration
• If the doc path ends with a slash, it means it is a directory
Multipurpose Internet Mail Extensions (MIME)

• Originally developed for email


• Used to specify to the browser the form of a file returned by the
server (attached by the server to the beginning of the document)
• Type specifications
• Form:
type/subtype
• Examples: text/plain, text/html, image/gif, image/jpeg Server gets
type from the requested file name’s suffix (.html implies text/html)
• Browser gets the type explicitly from the server
• Subtype begins with x-
e.g., video/x-msvideo
• Experimental types require the server to send a helper application or
plug-in so the browser can deal with the file
The HyperText Transfer Protocol

• The protocol used by ALL Web communications


• Request Phase
• Form:
HTTP method domain part of URL HTTP ver.
Header fields
blank line
Message body
• An example of the first line of a request:
GET /degrees.html HTTP/1.1
The HyperText Transfer Protocol: Methods

• GET - Fetch a document


• POST - Execute the document, using the data in body
• HEAD - Fetch just the header of the document
• PUT - Store a new document on the server
• DELETE - Remove a document from the server
HTTP Headers

• Four categories of header fields:


General, request, response, & entity

• Common request fields:


Accept: text/plain
Accept: text/*
If-Modified_since: date

• Common response fields:


Content-length: 488
Content-type: text/html

- Can communicate with HTTP without a browser


> telnet blanca.uccs.edu http
GET /respond.html HTTP/1.1
Host: blanca.uccs.edu
HTTP Response

• Form:
Status line
Response header fields
blank line
Response body
• Status line format:
HTTP version status code explanation
• Example: HTTP/1.1 200 OK
(Current version is 1.1)
• Status code is a three-digit number; first digit specifies the general status
1 => Informational
2 => Success
3 => Redirection
4 => Client error
5 => Server error
• The header field, Content-type, is required
HTTP Response Example

HTTP/1.1 200 OK
Date: Tues, 18 May 2004 16:45:13 GMT
Server: Apache (Red-Hat/Linux)
Last-modified: Tues, 18 May 2004 16:38:38 GMT
Etag: "841fb-4b-3d1a0179"
Accept-ranges: bytes
Content-length: 364
Connection: close
Content-type: text/html, charset=ISO-8859-1
• Both request headers and response headers must be followed by a blank line
Origins and Evolution of HTML

➢ HTML was defined with SGML

➢ HyperText Markup Language


➢ Not a procedural programming language like C
➢ Markup language: Identify elements of a page so that a browser can render that page on your computer screen
➢ Original intent of HTML: General layout of documents that could be displayed by a wide variety of computers
➢ Recent versions:
HTML 4.0 – 1997. Introduced many new features and deprecated many older features
HTML 4.01 - 1999 - A cleanup of 4.0
XHTML 1.0 – 2000
Just 4.01 defined using XML, instead of SGML
XHTML 1.1 – 2001

➢ Reasons to use XHTML, rather than HTML:

HTML has lax syntax rules, leading to sloppy and sometime ambiguous documents
– XHTML syntax is much more strict, leading to clean and clear documents in a standard form

HTML processors do not even enforce the few syntax rule that do exist in HTML

The syntactic correctness of XHTML documents can be validated


Common Tags
• Always include the <HTML>…</HTML> tags
• Comments placed inside <!--…--> tags
• HTML documents
• HEAD section
• Info about the document
• Info in header not generally rendered in display window
• TITLE element names your Web page
• BODY section
• Page content
• Includes text, images, links, forms, etc.
• Elements include backgrounds, link colors and font faces
• P element forms a paragraph, blank line before and after
Commonly used tags
1. html
2. Head
3. Body
4. Title
5. Header: <h1> to <h6>
6. center
7. Paragraph: <p>
8. Text Styling: <u> underline, align attribute- left , right or center, <i> italics, <b> bold
9. anchor tag: <a href=“”> click </a>
10. image: <img> - attributes src, height, width, border, alt
11. subscript and supersubscript: <sub>, <sup>
12. del: strike out text <del>
13. Line break: <br>
14. <hr>
15. list: <ul>, <li>, <ol>
16. Table
17. Form
18. input
19. Select
20. Textarea
21. Button
22. Frame and frameset
Basic Syntax

➢ Elements are defined by tags (markers)


Tag format:

• Opening tag: <name>

• Closing tag: </name>

The opening tag and its closing tag together specify a container for the content they enclose

➢ Not all tags have content

If a tag has no content, its form is <name />

➢ The container and its content together are called an element

➢ If a tag has attributes, they appear between its name and the right bracket of the opening tag

➢ Comment form: <!-- … -->

➢ Browsers ignore comments, unrecognizable tags, line breaks, multiple spaces, and tabs

➢ Tags are suggestions to the browser, even if they are recognized by the browser
HTML Document Structure

➢ Every XHTML document must begin with:

➢ Document Type Definition

➢ <html>, <head>, <title>, and <body> are required in every document

➢ The <title> tag is used to give the document a title, which is normally displayed in the browser’s window title bar (at the top of the display)

➢ Prior to XHTML 1.1, a document could have either a body or a frameset

➢ The whole document must have <html> as its root

➢ html must have the xmlns attribute:


Basic Text Markup

➢ How text section of XHTML document is formatted with XHTML tags


➢ Text is normally placed in paragraph elements
➢ Paragraph Elements
The <p> tag breaks the current line and inserts a blank line - the new line
gets the beginning of the content of the paragraph

➢ The browser puts as many words of the paragraph’s content as will fit in each
line
<!-- Greet.hmtl A trivial document -->
<html xmlns = ″http://www.w3.org/1999/xhtml″>
<head> <title> Our first document </title>
</head>
<body>
<p>
Greetings from your Webmaster!
</p>
</body>
</html>
➢ Line breaks: The effect of the <br /> tag is the same as that of <p>, except for the blank line
• No closing tag!
• “/” indicates both opening and closing
➢ Example of paragraphs and line breaks:

➢ Preserving White Space: pre Element


➢ Headings
• Six sizes, 1 - 6, specified with <h1> to <h6>
• 1, 2, and 3 use font sizes that are larger than the default font size
• 4 uses the default size
• 5 and 6 use smaller font sizes

<!-- headings.html
An example to illustrate headings
-->
<html xmlns = ″http://www.w3.org/1999/xhtml″>
<head> <title> Headings </title>
</head>
<body>
<h1> Aidan’s Airplanes (h1) </h1>
<h2> The best in used airplanes (h2) </h2>
<h3> "We’ve got them by the hangarful" (h3)
</h3>
<h4> We’re the guys to see for a good used
airplane (h4) </h4>
<h5> We offer great prices on great planes
(h5) </h5>
<h6> No returns, no guarantees, no refunds,
all sales are final (h6) </h6>
</body>
</html>
➢ Blockquotes

• Content of <blockquote>

• To set a block of text off from the normal flow and appearance of text Browsers often indent, and sometimes italicize
➢ Font Styles and Sizes (can be nested)

• Boldface - <b>

• Italics - <i>

• Larger - <big>

• Smaller - <small>

• Monospace - <tt>
The <big> sleet <big> in <big> <i> Crete The sleet in Crete
</i><br /> lies </big> completely </big>
in </big> the street lies completely in the street
➢ These tags are not affected if they appear in the content of a <blockquote>, unless there is a conflict (e.g., italics)
➢ Superscripts and subscripts
• Subscripts with <sub>
• Superscripts with <sup>
Example: x<sub>2</sub><sup>3</sup> Display: x23
➢ Inline versus block elements
Block elements CANNOT be nested in inline elements
➢ All of this font size and font style stuff can be done with style sheets, but these tags are not yet deprecated
➢ Character Entities

➢ Horizontal rules
<hr /> draws a line across the display, after a line break
➢ The meta element (for search engines) Used to provide additional information about a document, with attributes, not content
Images
➢ GIF (Graphic Interchange Format)
8-bit color (256 different colors)
➢ JPEG (Joint Photographic Experts Group)
24-bit color (16 million different colors)
➢ Both use compression, but JPEG compression is better
➢ Images are inserted into a document with the <img /> tag with the src attribute
➢ The alt attribute is required by XHTML
Purposes:
1.Non-graphical browsers
2.Browsers with images turned off
<img src = "comets.jpg"
alt = "Picture of comets" />
The <img> tag has 30 different attributes, including width and height (in pixels)

➢ Portable Network Graphics (PNG)


Relatively new
Should eventually replace both gif and jpeg
<!-- image.html
An example to illustrate an image
-->
<html xmlns = ″http://www.w3.org/1999/xhtml″>
<head> <title> Images </title>
</head>
<body>
<h1> Aidan's Airplanes </h1>
<h2> The best in used airplanes </h2>
<h3> "We've got them by the hangarful"
</h3>
<h2> Special of the month </h2>
<p>
1960 Cessna 210 <br />
577 hours since major engine overhaul
<br />
1022 hours since prop overhaul
<br /><br />
<img src = "c210new.jpg"
alt = "Picture of a Cessna 210"/>
<br />
Buy this fine airplane today at a
remarkably low price <br />
Call 999-555-1111 today!
</p>
</body>
</html>
Hypertext Links
➢ Hypertext is the essence of the Web!
➢ A link is specified with the href (hypertext reference) attribute of <a> (the anchor tag)
• The content of <a> is the visual link in the document
• If the target is a whole document (not the one in which the link appears), the target need not be specified in
the target document as being the target
➢ Note: Relative addressing of targets is easier to maintain and more portable than absolute addressing
<!-- link.html
An example to illustrate a link
-->
<html xmlns = ″http://www.w3.org/1999/xhtml″>
<head> <title> Links </title>
</head>
<body>
<h1> Aidan's Airplanes </h1>
<h2> The best in used airplanes </h2>
<h3> "We've got them by the hangarful"
</h3>
<h2> Special of the month </h2>
<p>
1960 Cessna 210 <br />
<a href = "C210data.html">
Information on the Cessna 210 </a>
</p>
</body>
</html>
➢ If the target is not at the beginning of the document, the target spot must be marked
➢ Target labels can be defined in many different tags with the id attribute, as in
<h1 id = "baskets"> Baskets </h1>
➢ The link to an id must be preceded by a pound sign (#); If the id is in the same document, this target could be
<a href = "#baskets">
What about baskets? </a>
➢ If the target is in a different document, the document reference must be included
<a href = "myAd.html#baskets”> Baskets </a>
➢ Style note: a link should blend in with the surrounding text, so reading it without taking the link should not be made less pleasant
➢ Links can have images:
<a href = "c210data.html“>
<img src = "smallplane.jpg"
alt = "Small picture of an airplane " />
Info on C210 </a>
Lists
➢ Unordered lists
➢ The list is the content of the <ul> tag
➢ List elements are the content of the <li> tag
<h3> Some Common Single-Engine Aircraft </h3>
<ul>
<li> Cessna Skyhawk </li>
<li> Beechcraft Bonanza </li>
<li> Piper Cherokee </li>
</ul>
➢ Ordered lists
The list is the content of the <ol> tag
Each item in the display is preceded by a sequence value

<h3> Cessna 210 Engine Starting Instructions


</h3>
<ol>
<li> Set mixture to rich </li>
<li> Set propeller to high RPM </li>
<li> Set ignition switch to "BOTH" </li>
<li> Set auxiliary fuel pump switch to
"LOW PRIME" </li>
<li> When fuel pressure reaches 2 to 2.5
PSI, push starter button </li>
</ol>
➢ Nested lists
• Any type list can be nested inside any type list
• The nested list must be in a list item

Definition lists (for glossaries, etc.)


• List is the content of the <dl> tag
• Terms being defined are the content of the <dt> tag
• The definitions themselves are the content of the <dd> tag
<h3> Single-Engine Cessna Airplanes </h3>
<dl >
<dt> 152 </dt>
<dd> Two-place trainer </dd>
<dt> 172 </dt>
<dd> Smaller four-place airplane </dd>
<dt> 182 </dt>
<dd> Larger four-place airplane </dd>
<dt> 210 </dt>
<dd> Six-place airplane - high performance
</dd>
</dl>
Tables
➢ A table is a matrix of cells, each possibly having content. The cells can include almost any element
➢ Some cells have row or column labels and some have data
➢ A table is specified as the content of a <table> tag
➢ A border attribute in the <table> tag specifies a border between the cells. If border is set to "border", the browser’s default width border
is used
➢ The border attribute can be set to a number, which will be the border width. Without the border attribute, the table will have no lines!
➢ Tables are given titles with the <caption> tag, which can immediately follow <table>
• Each row of a table is specified as the content of a <tr> tag
• The row headings are specified as the content of a <th> tag
• The contents of a data cell is specified as the content of a <td> tag
<table border = "border">
<caption> Fruit Juice Drinks </caption>
<tr>
<th> </th>
<th> Apple </th>
<th> Orange </th>
<th> Screwdriver </th>
</tr>
<tr>
<th> Breakfast </th>
<td> 0 </td>
<td> 1 </td>
<td> 0 </td>
</tr>
<tr>
<th> Lunch </th>
<td> 1 </td>
<td> 0 </td>
<td> 0 </td>
</tr>
</table>
➢ A table can have two levels of column labels
• the colspan attribute must be set in the <th> tag to specify that the label must span some number of columns
<tr>
<th colspan = "3"> Fruit Juice Drinks </th>
</tr>
<tr>
<th> Orange </th>
<th> Apple </th>
<th> Screwdriver </th>
</tr>

➢ If the rows have labels and there is a spanning column label, the upper left corner must be made larger, using rowspan

<table border = "border">


<tr>
<td rowspan = "2"> </td>
<th colspan = "3"> Fruit Juice Drinks
</th>
</tr>
<tr>
<th> Apple </th>
<th> Orange </th>
<th> Screwdriver </th>
</tr>

</table>
➢ The align attribute controls the horizontal placement of the contents in a table cell
• Values are left, right, and center (default)
• align is an attribute of <tr>, <th>, and <td> elements
➢ The valign attribute controls the vertical placement of the contents of a table cell
• Values are top, bottom, and center (default)
• valign is an attribute of <th> and <td> elements
➢ The cellspacing attribute of <table> is used to specify the distance between cells in a table
➢ The cellpadding attribute of <table> is used to specify the spacing between the content of a cell and the inner walls of the cell

<table cellspacing = "50">


<tr>
<td> Colorado is a state of …
</td>
<td> South Dakota is somewhat…
</td>
</tr>
</table>

➢ Table Sections
• Header, body, and footer, which are the elements: thead, tbody, and tfoot
• If a document has multiple tbody elements, they are separated by thicker horizontal lines
Forms
➢ A form is the usual way information is gotten from a browser to a server
➢ HTML has tags to create a collection of objects that implement this information gathering
➢ The objects are called widgets (e.g., radio buttons and checkboxes)
➢ When the Submit button of a form is clicked, the form’s values are sent to the server
➢ All of the widgets, or components of a form are defined in the content of a <form> tag
➢ The only required attribute of <form> is action, which specifies the URL of the application that is to be called when the Submit button is clicked

➢ The method attribute of <form> specifies one of the two possible techniques of transferring the form data to the server, get and post
➢ Widgets
Many are created with the <input> tag
The type attribute of <input> specifies the kind of widget being created
1. Text
• Creates a horizontal box for text input
• Default size is 20; it can be changed with the size attribute
• If more characters are entered than will fit, the box is scrolled (shifted) left
➢ If you don’t want to allow the user to type more characters than will fit, set maxlength, which causes excess input to be ignored
<input type = "text" name = "Phone"
size = "12" >
2. Checkboxes - to collect multiple choice input
• Every checkbox requires a value attribute, which is the widget’s value in the form data when the checkbox is ‘checked’
• A checkbox that is not ‘checked’ contributes no value to the form data
• By default, no checkbox is initially ‘checked’
• To initialize a checkbox to ‘checked’, the checked attribute must be set to "checked“

Grocery Checklist
<form action = "">
<p>
<input type = "checkbox" name ="groceries"
value = "milk" checked = "checked">
Milk
<input type = "checkbox" name ="groceries"
value = "bread">
Bread
<input type = "checkbox" name = "groceries"
value= "eggs">
Eggs
</p>
</form>
➢ Radio Buttons –
• collections of checkboxes in which only one button can be ‘checked’ at a time
• Every button in a radio button group MUST have the same name

➢ If no button in a radio button group is ‘pressed’, the browser often ‘presses’ the first one
Age Category
<form action = "">
<p>
<input type = "radio" name = "age"
value = "under20" checked = "checked"> 0-19
<input type = "radio" name = "age"
value = "20-35"> 20-35
<input type = "radio" name = "age"
value = "36-50"> 36-50
<input type = "radio" name = "age"
value = "over50"> Over 50
</p>
</form>
➢ Menus - created with <select> tags
➢ There are two kinds of menus, those that behave like checkboxes and those that behave like radio buttons (the default)
➢ Menus that behave like checkboxes are specified by including the multiple attribute, which must be set to "multiple"
➢ The name attribute of <select> is required
➢ The size attribute of <select> can be included to specify the number of menu items to be displayed (the default is 1)
If size is set to > 1 or if multiple is specified, the menu is displayed as a pop-up menu
➢ Text areas - created with <textarea>
• Usually include the rows and cols attributes to specify the size of the text area
• Default text can be included as the content of <textarea>
• Scrolling is implicit if the area is overfilled
Please provide your employment aspirations
<form action = "">
<p>
<textarea name = "aspirations" rows = "3”
cols = "40">
(Be brief and concise)
</textarea>
</p>
</form>
➢ Reset and Submit buttons
Both are created with <input>
<input type = "reset" value = "Reset Form">
<input type = "submit” value = "Submit Form">
Submit has two actions:
1. Encode the data of the form
2. Request that the server execute the server-resident program specified as the value of the action
attribute of <form>
A Submit button is required in every form
Frames
➢ Frames are rectangular sections of the display window, each of which can display a different document
➢ Because frames are no longer part of XHTML, you cannot validate a document that includes frames
➢ The <frameset> tag specifies the number of frames and their layout in the window
<frameset> takes the place of <body>
Cannot have both!
<frameset> must have either a rows attribute or a cols attribute, or both (usually the case)
Default is 1
➢ The possible values for rows and cols are numbers, percentages, and asterisks
A number value specifies the row height in pixels - Not terribly useful!
A percentage specifies the percentage of total window height for the row - Very useful
➢ An asterisk after some other specification gives the remainder of the height of the window
Examples:
<frameset rows = "150, 200, 300">

<frameset rows = "25%, 50%, 25%">

<frameset rows = "50%, 20%, *" >

<frameset rows = "50%, 25%, 25%"


cols = "40%, *">
➢ The <frame> tag specifies the content of a frame
➢ The first <frame> tag in a <frameset> specifies the content of the first frame, etc.
• Row-major order is used
• Frame content is specified with the src attribute
• Without a src attribute, the frame will be empty (such a frame CANNOT be filled later)
➢ If <frameset> has fewer <frame> tags than frames, the extra frames are empty
➢ Scrollbars are implicitly included if needed (they are needed if the specified document will not fit)
➢ If a name attribute is included, the content of the frame can be changed later (by selection of a link in some other frame)

Note: the Frameset standard must be specified in the DOCTYPE declaration


<!-- contents.html
The contents of the first frame of
frames.html, which is the table of
contents for the second frame
-->
<html xmlns = ″http://www.w3.org/1999/xhtml″>
<head> <title> Table of Contents Frame
</title>
</head>
<body>
<h4> Fruits </h4>
<ul>
<li> <a href = "apples.html"
target = "descriptions">
apples </a>
<li> <a href = "bananas.html"
target = "descriptions">
bananas </a>
<li> <a href = "oranges.html"
target = "descriptions">
oranges </a>
</ul>
</body>
</html>
Nested frames - to divide the screen in more interesting ways
Syntactic Differences between HTML & XHTML
• Case sensitivity
• Closing tags
• Quoted attribute values
• Explicit attribute values
• id and name attributes
• Element nesting
XHTML
•To describe the general form and layout of documents
•An XHTML document is a mix of content and controls
•Controls are tags and their attributes
•Tags often delimit content and specify something
about how the content should be arranged in the
document
•Attributes provide additional information about the
content of a tag
Creating XHTML documents
• XHTML editors - make document creation easier

• Shortcuts to typing tag names, spell-checker,

• WYSIWYG XHTML editors

• Need not know XHTML to create XHTML documents


HTML XHTML

HTML or HyperText Markup Language is the main XHTML (Extensible HyperText Markup Language) is a
markup language for creating web pages and other family of XML markup languages that mirror or
information that can be displayed in a web browser. extend versions of the widely used Hypertext Markup
Language (HTML), the language in which web pages
are written
Internet media type: text/html application/xhtml+xml

Can have empty/open tags e.g. <br>, <p>. All the unclosed tags must be closed e.g. <br/>,
<p></p>.
Attributes have quotes as optional e.g. <font Attributes have quotes mandatory e.g. <font
color=#ff0000>. color=”#ff0000?>.
Case insensitive:The tags and attributes can be of Case sensitive:The tags and attributes must be of
uppercase or lowercase as per the preference. lowercase.
HTML is not mandatory for one root element. XHTML documents must have one root element.
Explore more on:

<img src="img_test.jpg" width="500" height="600">


<p style="color:red">This is a paragraph.</p>
<h1 style="font-size:60px;">Heading 1</h1>
<body style="background-color:powderblue;">
<h1 style="font-family:verdana;">This is a heading</h1>
<h1 style="font-size:300%;">This is a heading</h1>
<h1 style="text-align:center;">Centered Heading</h1>
Code
<html>
<body>
<h2>Unordered List with Disc Bullets</h2>
<ul style="list-style-type:circle;">
<li>Coffee</li>
<li>Tea</li>
<li>Milk</li>
</ul>
</body>
</html>
Introduction to CSS

➢ The CSS specification was developed in 1996


➢ CSSs provide the means to control and change presentation of HTML
documents
➢ CSS is not technically HTML, but can be embedded in HTML documents
➢ Style sheets allow you to impose a standard style on a whole document,
or even a whole collection of documents
➢ Style is specified for a tag by the values of its properties
Levels of Style Sheets
➢ There are three levels of style sheets
➢ Inline - specified for a specific occurrence of a tag and apply only to that tag
– This is fine-grain style, which defeats the purpose of style sheets - uniform style
➢ Document-level style sheets - apply to the whole document in which they appear
➢ External style sheets - can be applied to any number of documents
➢ When more than one style sheet applies to a specific tag in a document, the lowest level style sheet has
precedence
➢ In a sense, the browser searches for a style property spec, starting with inline, until it finds one (or there isn’t
one)
➢ Inline style sheets appear in the tag itself
➢ Document-level style sheets appear in the head of the document
➢ External style sheets are in separate files, potentially on any server on the Internet
➢ Written as text files with the MIME type text/css
Linking an External Style sheet

A <link> tag is used to specify that the browser is to fetch and use an external style sheet file
Style Specification Formats
➢ Format depends on the level of the style sheet
Inline:
➢ Style sheet appears as the value of the style attribute General form:

➢ Format for Document-level


• Style sheet appears as a list of rules that are the content of a <style> tag
• The <style> tag must include the type attribute, set to "text/css"
• The list of rules must be placed in an HTML comment, because it is not HTML
• Comments in the rule list must have a different form - use C comments (/*…*/)

➢ General Form, Document Level


<style type = "text/css">
<!--
rule list
-->
</style>
➢ Form of the rules:
selector {list of property/values}
➢ Each property/value pair has the form:
property: value
➢ Pairs are separated by semicolons, just as in the value of a <style> tag
Selector Forms: Simple
➢ The selector is a tag name or a list of tag names, separated by commas
• h1, h3
• p
➢ Contextual selectors
• ol ol li
➢ Class Selectors
• Used to allow different occurrences of the same tag to use different style specifications
• A style class has a name, which is attached to a tag name
• p.narrow {property/value list}
• p.wide {property/value list}
• The class you want on a particular occurrence of a tag is specified with the class attribute of the tag
For example,
<p class = "narrow">
...
</p>
...
<p class = "wide">
...
</p>
➢ Generic Selectors
• A generic class can be defined if you want a style to apply to more than one kind of tag
• A generic class must be named, and the name must begin with a period
Example,
.really-big { … }
Use it as if it were a normal style class
<h1 class = "really-big"> … </h1>
...
<p class = "really-big"> … </p>
➢ id Selectors
• An id selector allow the application of a style to one specific element
• General form:
#specific-id {property-value list}
Example:
#section14 {font-size: 20}

➢ Pseudo Classes
• Pseudo classes are styles that apply when something happens, rather than because the target element simply exists
• Names begin with colons
• hover classes apply when the mouse cursor is over the element
• focus classes apply when an element has focus

<!-- pseudo.html -->


<html xmlns = "http://www.w3.org/1999/xhtml">
<head> <title> Checkboxes </title>
<style type = "text/css">
input:hover {color: red;}
input:focus {color: green;}
</style>
</head>
<body>
<form action = "">
<p>
Your name:
<input type = "text" />
</p>
</form>
</body>
</html>
➢ There are 60 different properties in 7 categories: Properties
• Fonts
• Lists
• Alignment of text
• Margins
• Colors
• Backgrounds
• Borders
➢ Property Values
• Keywords - left, small, … Not case sensitive
• Length - numbers, maybe with decimal points
• Units: px – pixels, in – inches, cm – centimeters, mm – millimeters, pt – points, pc - picas (12 points)
• em - height of the letter ‘m’
• ex-height - height of the letter ‘x’
• No space is allowed between the number and the unit specification e.g., 1.5 in is illegal
• Percentage - just a number followed immediately by a percent sign
• URL values: url(protocol://server/pathname)
• Colors, Color name, rgb(n1, n2, n3)
• Numbers can be decimal or percentages
• Hex form: #XXXXXX
• Property values are inherited by all nested tags, unless overridden
The border-style property specifies what kind of border to display.
The following values are allowed:
•dotted - Defines a dotted border
•dashed - Defines a dashed border
•solid - Defines a solid border
•double - Defines a double border
•groove - Defines a 3D grooved border. The effect depends on the
border-color value
•ridge - Defines a 3D ridged border. The effect depends on the border-
color value
•inset - Defines a 3D inset border. The effect depends on the border-
color value
•outset - Defines a 3D outset border. The effect depends on the
border-color value
•none - Defines no border
•hidden - Defines a hidden border
EXECUTE -1
p.dotted {border-style: dotted;} EXECUTE -2
p.dashed {border-style: dashed;}
p.solid {border-style: solid;} p{
p.double {border-style: double;} border: 2px solid red;
p.groove {border-style: groove;}
p.ridge {border-style: ridge;} border-radius: 5px;
p.inset {border-style: inset;}
p.outset {border-style: outset;}
}
p.none {border-style: none;}
p.hidden {border-style: hidden;}
p.mix {border-style: dotted dashed solid double;}

EXECUTE -3
border-top-style: dotted;
border-right-style: solid;
border-bottom-style: dotted;
border-left-style: solid;
EXECUTE -4
p { EXECUTE -5
margin-top: 100px; p {
margin-bottom: 100px; margin: 25px 50px 75px 100px;
margin-right: 150px; }
margin-left: 80px;
}

EXECUTE -6
h1 {
text-align: center;
}
EXECUTE -7 EXECUTE -8
p { h1 {
font-family: "Times New Roman", Times, serif; font-size: 40px;
} }

EXECUTE -9
p.normal {
font-style: normal;
}

p.italic {
font-style: italic;
}

p.oblique {
font-style: oblique;
}
EXECUTE -10 EXECUTE -11
p.normal { p.normal {
font-weight: normal; font-variant: normal;
} }

p.thick { p.small {
font-weight: bold; font-variant: small-caps;
} }
EXECUTE -12
a:link {
color: red;
}
/* visited link */
a:visited {
color: green;
}
/* mouse over link */
a:hover {
color: hotpink;
}
/* selected link */
a:active {
color: blue;
}
ul.a { ul.a {
list-style-type: circle; list-style-position: outside;
} }
ul.b { ul.b {
list-style-type: square; list-style-position: inside;
} }
ol.c {
list-style-type: upper-roman;
}

ol.d {
list-style-type: lower-alpha;
} table, th, td {
border: 1px solid black;
}
Font Properties
➢ font-family Value: is a list of font names - browser uses the first in the list it has
font-family: Arial, Helvetica, Courier
Generic fonts: serif, sans-serif, cursive, fantasy, and monospace (defined in CSS)
➢ Browser has a specific font for each
If a font name has more than one word, it should be single-quoted
➢ font-size: Possible values: a length number or a name, such as smaller, xx-large, etc.
➢ font-style: italic, oblique (useless), normal
➢ font-weight - degrees of boldness bolder, lighter, bold, normal
Could specify as a multiple of 100 (100 – 900)
font: bolder 14pt Arial Helvetica
Order must be: style, weight, size, name(s)
List properties

On <li>, list-style-type applies to just that item


<h3> Some Common Single-Engine Aircraft </h3>
<ul>
<li style = "list-style-type: disc">
Cessna Skyhawk </li>
<li style = "list-style-type: square">
Beechcraft Bonanza </li>
<li style = "list-style-type: circle">
Piper Cherokee </li>
</ul>

Could use an image for the bullets in an unordered list


Example:
<li style = "list-style-image:
url(bird.jpg)">
On ordered lists - list-style-type can be used to change the sequence values
Property value Sequence type First four
Decimal Arabic numerals 1, 2, 3, 4
upper-alpha Uc letters A, B, C, D
lower-alpha Lc letters a, b, c, d
upper-roman Uc Roman I, II, III, IV
lower-roman Lc Roman i, ii, iii, iv

CSS2 has more, like lower-greek and hebrew


➢ Could use an image for the bullets in an unordered list
Example:
<li style = "list-style-image:
url(bird.jpg)">
➢ On ordered lists - list-style-type can be used to change the sequence values
Property value Sequence type First four
Decimal Arabic numerals 1, 2, 3, 4
upper-alpha Uc letters A, B, C, D
lower-alpha Lc letters a, b, c, d
upper-roman Uc Roman I, II, III, IV
lower-roman Lc Roman i, ii, iii, iv
➢ CSS2 has more, like lower-greek and hebrew
Colors
➢ Color is a problem for the Web for two reasons:
1. Monitors vary widely 2. Browsers vary widely
➢ There are three color collections
• There is a set of 16 colors that are guaranteed to be displayable by all graphical browsers on all color monitors

• There is a much larger set, the Web Palette


216 colors, Use hex color values of 00, 33, 66, 99, CC, and FF, Inside back cover of this book has them
• Any one of 16 million different colors
The color property specifies the foreground color of elements

<style type = “text/css”>


th.red {color: red}
th.orange {color: orange}
</style>

<table border = "5">
<tr>
<th class = "red"> Apple </th>
<th class = "orange"> Orange </th>
<th class = "orange"> Screwdriver </th>
</tr>
</table>
The background-color property specifies the background color of elements
Alignment of Text

➢ The text-indent property allows indentation


• Takes either a length or a % value
➢ The text-align property has the possible values, left (the default), center, right, or justify
➢ Sometimes we want text to flow around another element - the float property
• The float property has the possible values, left, right, and none (the default)
• If we have an element we want on the right, with text flowing on its left, we use the default text-align value (left) for the
text and the right value for float on the element we want on the right
<img src = "c210.jpg"
style = "float: right" />
The Box Model
➢ Borders – every element has a border-style property
➢ Controls whether the element has a border and if so, the style of the border
• border-style values: none, dotted, dashed, and double
• border-width – thin, medium (default), thick, or a length value in pixels
• Border width can be specified for any of the four borders (e.g., border-top-width)
• border-color – any color
➢ Border color can be specified for any of the four borders (e.g., border-top-color)
➢ Margin – the space between the border of an element and its neighbor
element
➢ The margins around an element can be set with margin-left, etc. - just assign
them a length value
<img src = "c210.jpg " style = "float: right;
margin-left: 0.35in;
margin-bottom: 0.35in" />
➢ Padding – the distance between the content of an element and its border
Controlled by padding, padding-left, etc.
Background Images
➢ The background-image property
Repetition can be controlled
• background-repeat property
• Possible values: repeat (default), no-repeat, repeat-x, or repeat-y
• background-position property
• Possible values: top, center, bottom, left, or right
The <span> and <div> tags
➢ One problem with the font properties is that they apply to whole elements, which are often too large
Solution: a new tag to define an element in the content of a larger element - <span>
The default meaning of <span> is to leave the content as it is
<p>
Now is the <span> best time </span> ever!
</p>
Use <span> to apply a document style sheet to its content
<style type = "text/css">?
bigred {font-size: 24pt;
font-family: Ariel; color: red}
</style>
<p>
Now is the
<span class = "bigred">
best time </span> ever!
</p>

➢ The <span> tag is similar to other HTML tags, they can be nested and they have id and class attributes
➢ Another tag that is useful for style specifications: <div>
➢ Used to create document sections (or divisions) for which style can be specified
e.g., A section of five paragraphs for which you want some particular style

You might also like