HTML and CSS
HTML and CSS
Html Introduction
Html Tags – IMG, Form, Hyperlinks, Frames, Tables
Exercise
Cascading Style Sheets – Introduction
Advantages of CSS
Types of Style Sheets
Selectors
Key Concepts
Example
Introduction [Contd…]
Web Browser
➨ Establishes the connection to the specified Web server, at the
requested URL (Uniform Resource Locator (URL)
➨ Interprets and formats the information found on the server, and
displays the formatted information.
Web Server
➨ A computer that delivers/serves Web pages.
➨ Every Web server has an IP address and possibly a domain name.
E.g:I f you enter the URL http://www.yahoo.com/index.html in your
browser, this sends a request to the server whose domain name is
yahoo.com. The server then fetches the page named index.html
and sends it to your browser.
➨ Each Web server contains documents that are written in the
Hypertext Markup Language (HTML)
Absolute URLs
➨ Absolute URLs use a complete Internet address to give the location of
a resource.
➨ Examples:
http://msdn.microsoft.com/support/index.asp
http://msdn.microsoft.com/code/welcome.asp?frame=true
URL Basics
Relative URLs
➨ Relative URLs are used for accessing files when the full Internet
address is unnecessary.
➨ Examples:
index.asp
/index.asp
welcome.asp?frame=true
Fragment URLs
➨ Fragment URLs are used to access to a specific location within a URL.
➨ Examples:
http://www.someplace.com/shopping.html#books
Introduction - HTML Tags
Specifying Colspan
<table>
<tr> <td colspan=2>Heading</tr>
<tr><td> One Heading
<td> Two One Two
</tr>
</table>
Specifying Rowspan
<table border=1>
Two
<tr><td rowspan=2>One<td> Two One
Three
</tr>
<tr><td> Three</tr>
</table>
Frames [Contd…]
frame.html
<frameset cols="20%,80%">
<frame name="toolbar" src="toolbar.html">
<frame name="content" src="index.html">
</frameset>
toolbar.html
<a href="index.html" target="content">home</a>
<a href="products.html" target="content">products</a>
<a href="info.html" target="content">about us</a>
<a href="feedback.html" target="content">feedback</a>
Frames [Contd…]
Form Element
➨ The form has got two main attributes viz.. Action and Method.
➨ Action attribute is required. Methods are ‘get’ which is default and
‘post’
➨ Other attributes define the encoding type and event
handlers[javascript/vbscript]
➨ Here is an eg. of Form tag
<form action=URL method=get/post enctype=” multipart/form-data”
onSubmit [script – event handling] onReset[script]>
</form>
The action attribute has the url to which the Form data has to go
Using Forms in HTML [Contd…]
➨ The GET method submits the name/value pairs to the URL
specified in action attribute appending to the URL. eg
urlname?FirstName=value&SecondName=value
➨ This can be seen on the browser’s address bar
➨ The method POST submits the data as part of HTML Body
➨ The ENCTYPE is used to state the encoding type of the form
contents. Default being ‘application/x-www-form-urlencoded’.
➨ There are two attributes[onSubmit and onReset] which are used
w.r.t scripting is concerned.
➨ The ONSUBMIT event is triggered when a submit button is
clicked and from here the control can be passed on to any
function of a script
➨ eg. javascript or vbscript Usage: <form ….
OnSubmit=”javascript: return functionName()”> ---- </form>
Using Forms in HTML [Contd…]
➨ Basically this can be used whenever we want to invoke a
javascript/vbscript function on clicking on a ‘Submit’ button
➨ Whenever we use any form element in a web page it must be with
in <form></form> tags.
Input Elements
➨ button – Used to invoke a script function or to play around the
controls of form elements
➨ checkbox - Off/on
➨ file - Used for selecting user-selecting file
➨ hidden – to hold hidden form elements which do not appear on the
web page
➨ image – to make an image as equivalent to a Submit button
➨ password – to Mask the input entry
➨ radio – one entry choosing
➨ Reset – reset the form elements’ values
Using Forms in HTML [Contd…]
Hidden
➨ The hidden value enables to submit form information that’s invisible to
the user on the web page.
➨ Eg. <input type=”hidden” name=”Page”
value=”hiddenValue”>
Image
➨ This is same as a ‘Submit’ button, but the only difference is that it
replaces the stark Submit button with an Image. Otherwise it has the
same function.
➨ Eg. <input type=”image” src=”images/submit_Image”>
Using Forms in HTML [Contd…]
Password
➨ This is an input control where the text is masked with an asterisk.
Otherwise its similar to a text box.
➨ Eg. <input type=”password” name=“userpswd”>
Using Forms in HTML [Contd…]
Submit
➨ This is used to send the name/value pairs of the active form
elements to the URL
➨ Specified in the FORM declaration
➨ HTML specification enables multiple Submit buttons
➨ Its declared as <input type=”submit”>
Text
➨ This can be used to enter text of a single-line in a text box
➨ Eg. <input type=”text” name=”firstname” size=”15”
maxlength=”20”>
➨ The ‘size’ attribute sets the length of the text box
➨ The ‘maxlength’ attribute limits[No. of characters] the user for typing
text
➨ One more attribute is ’readonly’. This locks the cursor on focus of
the text box and does not allow the user to type any text
Using Forms in HTML [Contd…]
Select and Option Elements
➨ The SELECT element is used to create a list of choices either as a
drop-down menu or a list box. Each of the choices in the list is an
OPTION element
<SELECT name=”controlName” size=”controlWidth”
onChange=script>
<option value=”Value1”>First Option</option>
<option value=”Value2” selected>Second Option</option>
<option value=”Value3”>Third Option</option>
</SELECT>
➨ onChange is an event for Select box and directs the flow control to
the specified script function.
➨ The default value if not specified explicitly for an option tag would
be its content.
➨ The attribute selected leaves that option highlighted
Using Forms in HTML [Contd…]
Provide all necessary buttons to suite this form. The submit button is an image.
CSS
Inline Style
For example see the following snippet
<P style=“color: green”> Paragraph inline style </P>
Inside the style attribute comes style declarations. In this example, the P element is
being made green.
<BODY style=“color: #FFFFFF; background:#000000”> Paragraph
inline style </BODY>
In the above snippet we are applying the Inline style to the Body tag, which will give
the Black back ground to the body and White color for all the text which will appear
in the Body tag.
CSS [Contd…]
Disadvantage
➨ If the user downloads the page and if he forgot to
download the Linked CSS then he/she will not be able to
view the page with all the styles.
CSS [Contd…]
Selectors
To give you more freedom to select which elements your style is
applied to.
Attribute Selectors:
➨ Class
➨ ID
➨ The CLASS attribute enables you to apply declarations to a group of
elements that have the same value on the CLASS attribute
➨ All elements inside BODY can have a CLASS attribute
<HTML>
<TITLE>Class Attributes</TITLE>
<STYLE TYPE="text/css">
.boldtxt { font-weight: bold }
.nrmltxt { font-weight: normal }
</STYLE>
<BODY>
<P CLASS= boldtxt >This is Bold Text Line</P>
<P CLASS= nrmltxt >This is normal text line</P>
<P CLASS= boldtxt >Second Line of Bold Text</P>
<P CLASS= nrmltxt >Second Line of Normal Text</P>
</BODY>
</HTML>
CSS [Contd…]
ID Attribute:
The ID attribute works like the CLASS attribute with one important
difference –
➨ The HTML syntax of the element on which you want to use the ID
attribute resembles that of other elements with attributes; for example:
<P ID=undltxt>Underlined text</P>
CSS [Contd…]
Style Attribute:
➨ The STYLE attribute is actually a replacement for the whole selector
mechanism
➨ Instead of having a value that can be referred to in a selector (which is
what ID and CLASS have), the value of the STYLE attribute is actually
one or more CSS declarations.
➨ <P STYLE="text-decoration: underline">Underlined
text</P>
➨ Actual Implementation of Style Attribute
<HTML>
<TITLE>Class Attributes</TITLE>
<BODY>
<P STYLE="font-weight: bold">This is Bold Text Line</P>
<P STYLE="font-weight: normal">This is normal text
line</P>
</BODY>
</HTML>
CSS [Contd…]