Академический Документы
Профессиональный Документы
Культура Документы
UNIT 2
HTML AND XHTML
FORMS
<body>
<h2>Text Input</h2>
<form>
First name:<br>
<input type="text" name="firstname">
<br>
Last name:<br>
<input type="text" name="lastname">
</form>
<p>Note that the form itself is not visible.</p>
<p>Also note that the default width of a text input field is 20 characters.</p>
</body>
</html>
RADIO BUTTON:
Radio buttons are special type of buttons which allows the user to select only
individual option
Radio buttons are created using the input tag with the type attribute having the value
radio.
When radio buttons are created, values must be provided with the help of value
attribute.
All the radio buttons which are created would have same name. This is because the
radio buttons are group elements.
If one of the radio buttons has to be selected as soon as the web page is loaded,
checked attribute should be used. The value also would be checked.
<html >
<head> <title> Radio </title>
</head>
<body>
<p>
Age Category </p>
<form action = ""> <p>
<label><input type = "radio" name = "age" value = "under20" checked =
"checked" /> 0-19 </label>
<label><input type = "radio" name = "age" value = "20-35" /> 20-35 </label>
<label><input type = "radio" name = "age" value = "36-50" /> 36-50 </label>
<label><input type = "radio" name = "age" value = "over50" /> Over 50 </label>
</p>
</form>
</body>
</html
CHECKBOX
Check box is a type of input using which multiple options can be selected.
Check box can also be created using the <input> tag with the type having the value
“checkbox”.
During the creation of check box, the value should be provided using the value
attribute.
All the checkbox which are created would have the same name because they are
group elements.
If one of the check box have to be selected as soon as the page is loaded, checked
attribute should be used with the value checked.
<html >
<head> <title> Checkboxes </title></head>
<body>
<p>Grocery Checklist </p>
<form action = ""> <p>
<label> <input type = "checkbox" name = "groceries" value = "milk" checked =
"checked" /> Milk </label>
<label> <input type = "checkbox" name = "groceries" value = "bread" /> Bread
</label>
<label> <input type = "checkbox" name = "groceries" value = "eggs" /> Eggs
</label>
</p>
</form>
</body>
</html>
SELECT
Menu items is another type of input that can be created on the page.
To create the menu item, <select> tag is used.
To insert the item in the menu, <option> tag is used.
<html >
<head> <title> Menu </title>
</head>
<body>
<p> Grocery Menu - milk, bread, eggs, cheese </p>
<form action = ""> <p>
With size = 1 (the default) <select name = "groceries">
<option> milk </option>
<option> bread </option>
<option> eggs </option>
<option> cheese </option>
</select>
</p>
</form>
</body>
</html>
TEXTAREA:
Text area is a type of input using which multiple statements can be entered.
Text area is created using <textarea> tag.
Text area should have the name.
During the creation of text area, it should be mentioned how many sentences can be
entered. This is done using rows attribute.
Similarly, it should also be mentioned how many characters can be entered in a line.
This is done using
cols attribute.
If the value given to rows is exceeded i.e. if users enter sentences more than specified,
the scroll bar automatically appears.
<html >
<head> <title> Textarea </title></head>
<body>
<p>Please provide your employment aspirations </p>
<form action = "handler">
<p><textarea name = "aspirations" rows = "3" cols = "40"> </textarea></p>
</form>
</body>
</html>
ACTION BUTTON:
The Reset button clears all of the controls in the form to their initial states.
The Submit button has two actions:
o First, the form data is encoded and sent to the server
</body>
</html>
FRAMES
HTML frames are used to divide your browser window into multiple sections where
each section can load a separate HTML document.
A collection of frames in the browser window is known as a frameset.
The window is divided into frames in a similar way the tables are organized: into
rows and columns.
To use frames on a page we use <frameset> tag instead of <body> tag. The
<frameset> tag defines, how to divide the window into frames.
The rows attribute of <frameset> tag defines horizontal frames and cols attribute
defines vertical frames.
Each frame is indicated by <frame> tag and it defines which HTML document shall
open into the frame.
There are 3 kinds of values for rows and columns numbers, percentage and asterisk.
When number is used it specifies in pixels. When percentage is given number is
followed by % sign.
Ex:
<frameset rows=“200 , 300, 400”>
<frameset rows= “22%, 33%, 45%”>
<frameset rows= “22%, 33%,* “>
<frameset rows= “33%, 33%, 33% “ cols=“25%, *”>
Content of a frame is specified as the value of the src attribute in the <frame> tag
<frame src= “example.html”>
<frameset cols="25%,25%,25%,*">
<frame src="frames1.html">
<frame src="frame2.html">
<frame src="frame3.html">
<frame src="frame4.html">
</frameset>
</html>
Frames1.html
<body>
<h1> Frame1</h1>
<p> content of frame 1 </p>
</body>
</html>
Frames2.html
<body>
<h1> Frame2</h1>
<p> content of frame 2 </p>
</body>
</html>
Frames3.html
<body>
<h1> Frame3</h1>
<p> content of frame 3 </p>
</body>
</html>
Frames4.html
<body>
<h1> Frame4</h1>
<p> content of frame 4</p>
</body>
</html>
<frameset rows="150,150,150,*">
<frame src="frame_1.html">
<frame src="frame_2.html">
<frame src="frame_3.html">
<frame src="frame_4.html">
</frameset>
</html>
<frameset cols=“30%,30%,*">
<frameset rows=“40%,*">
<frame src="frame_1.html">
<frame src="frame_2.html">
</frameset> <frame src="frame_3.html">
<frame src="frame_4.html">
</frameset> </html>
<frameset cols="30%,30%,*">
<frame src="frame_1.html">
<frameset rows="50%,50%">
<frame src="frame_2.html">
<frame src="frame_3.html">
</frameset>
<frame src="frame_4.html">
</frameset>
</html>
<frameset cols="*,*">
<frame src="frame_1.html">
<frameset rows="*,*">
<frame src="frame_2.html">
<frameset cols="*,*">
<frame src="frame_3.html">
<frame src="frame_4.html">
</frameset>
</frameset>
</frameset>
</html>
Closing tags Closing tags may be omitted All elements must have closing tag
Quoted Special characters are quoted. Numeric All attribute values must be quoted
attribute values values are rarely quoted. including numbers
Explicit Some attribute values are implicit. All attribute values must be explicitly
attribute values For example: <table border>. stated
A default value for border is assumed
id and name Both id and name attributes are encouraged Use of id is encouraged and use of name
attributes is discouraged
Element nesting Rules against improper nesting of elements All nesting rules are strictly enforced
(for example: a form element cannot contain
another form element) are not enforced.
INTRODUCTION
Inline level: Inline style sheets are specified for a specific occurrence of a tag and
apply only to the content of that tag.
Document Level : Document-level style specifications appear in the document
head section and apply to the whole body of the document.
External Level: External style sheets are not part of the documents to which they
apply. They are stored separately and are referenced in all documents that use
them. They are written as text files with MIME type text/css.
<html >
<head>
<title> Our first document </title>
<style>
h2 {font-size: 32pt; font-weight: bold;font-family: 'Times New Roman';}
h3,h4 { font-size: 18pt; font-family: 'Courier New'; font-style:italic;
font-weight:bold}
</style>
</head> <body>
<h1> Twinkle twinkle little star</h1>
<h2> how I wonder </h2>
<h3>what you are ???</h3>
<h4>up above the world so high</h4>
<h5> like a diamond</h5>
<h6> in the sky.</h6>
</body>
</html>
SELECTORS FORMS
The selector can have a variety of forms:
1.Simple selector form
2. Class selector
3. Generic selector
4. Id selector
5. Universal selector
6. Pseudo classes
Simple Selector Forms:
In case of simple selector, a tag is used. If the properties of the tag are changed,
then it reflects at all the places when used in the program. The selector can be any
tag. If the new properties for a tag are not mentioned within the rule list, then the
browser uses default behaviour of a tag.
<html>
<head>
<title>Sample CSS</title>
<style type = "text/css">
p{ font-size: 50pt; color: Red;
}</style>
</head>
<body>
<p>welcome </p>
<p>college </p>
</body>
</html>
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 the tag’s name with
a period.
<head>
<title>Sample CSS</title>
<style type = "text/css">
p.one
{
font-size: 25pt;
color: Red;
}
p.two
{
font-size: 50pt;
color: green;
}
</style>
</head>
<body>
<p class = "one">Web technologies</p>
<p class = "two">Web technologies</p>
</body>
</html>
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 without a tag
name in its name.
<html>
<head>
<title>Sample CSS</title>
id Selectors:
An id selector allows the application of a style to one specific element.
<html>
<head>
<title>Sample CSS</title>
<style type = "text/css">
#one
{
color: purple;
}
#two
{
color: orange;
}
</style>
</head>
<body>
<p id = "two">Web technologies</p>
<h1 id = "one">Web technologies</h1>
</body>
</html>
Universal Selectors:
The universal selector, denoted by an asterisk (*), applies its style to all elements in a
document. <html>
<head>
<title>Sample CSS</title>
<style type = "text/css">
*
{
color: purple;
}
</style>
</head>
<body>
<h1>Web technologies</h1>
<h2>Web technologies</h2>
<h3>Web technologies</h3>
<p>Web technologies</p>
</body>
</html>
Pseudo Classes
Pseudo classes are styles that apply when something happens, rather than because the
target element simply exists. Names of pseudo classes begin with colons .
There are 4 pseudo classes: link, visited, hover and focus.
Example:
<head>
<title>Sample CSS</title>
<style type = "text/css">
input:focus{ color: purple; font-size:100; }
input:hover{ color: violet; font-size:40;}
</style>
</head>
<body>
<form action = " ">
<p>NAME:<input type = "text" /></p>
</body>
</html>
Contextual selector
Use CSS contextual selector when you want to specify an element
within the context of its container (parent) element.
Example:
<!DOCTYPE html>
<head>
<style>
ol>li {color:red; }
</style>
</head>
<body>
<h2>EATABLES</h2>
<ol>
<li>JUICES</li>
<li>ICE-CREAMS</li>
<ul>
<li>STRAWBERRY</li>
<li>MANGO</li>
</ul>
<li>CHOCOLATES</li>
</ol>
<ol>
<h2>COLORS</h2>
<li>red</li>
<li>blue</li>
<li>green</li>
</ol>
</body>
</html>
FONT PROPERTIES
Font Families:
The font-family property is used to specify a list of font names. The browser uses
the first font in the list that it supports. For example, the property:
font-family: Arial, Helvetica, Futura
tells the browser to use Arial if it supports that font. If not, it will use Helvetica if
it supports it. If the browser supports neither Arial nor Helvetica, it will use Futura if
it can. If the browser does not support any of the specified fonts, it will use an
alternative of its choosing.
If a font name has more than one word, the whole name should be delimited by
single quotes, as in the following example:
font-family: ‘Times New Roman’
Font Sizes:
The font-size property does what its name implies. For example, the following
property specification sets the font size for text to 10 points:
font-size: 10pt
Many relative font-size values are defined, including xx-small, x-small, small,
medium, large, x-large, and xx-large. In addition, smaller or larger can be specified.
Furthermore, the value can be a percentage relative to the current font size.
Font Variants:
The default value of the font-variant property is normal, which specifies the usual
character font.
This property can be set to small-caps to specify small capital characters. These
characters are all uppercase, but the letters that are normally uppercase are somewhat
larger than those that are normally lowercase.
Font Styles:
The font-style property is most commonly used to specify italic, as in
font-style: italic
Font Weights:
Font Shorthands:
If more than one font property must be specified, the values can be stated in a list as
the value of the font property.
The order in which the property values are given in a font value list is important.
The order must be as follows: The font names must be last, the font size must be
second to last, and the font style, font variant, and font weight, when they are
included, can be in any order but must precede the font size and font names.
font: bold 14pt ‘Times New Roman’
Example:
<html>
<head>
<title>Font Properties</title>
<style type = "text/css">
p.one
{
font-family: 'lucida calligraphy';
font-weight:bold;
font-size:75pt;
color: purple;
}
p.three
{
font: small-caps italic bold 50pt 'times new roman'
}
</style>
</head>
<body>
<p class = "one">Web technologies</p>
<p class = "three">Web technologies</p>
</body>
</html>
Letter-spacing – value is any length property value controls amount of space between
characters in text
Eg: letter-spacing: 3px
<html >
<head> <title> Text decoration </title>
<style type = "text/css">
p.through {text-decoration: line-through}
p.over {text-decoration: overline}
LIST PROPERTIES
<html>
<head>
<title>CSS Bullets</title>
<style type = "text/css">
li.one{list-style-type:disc}
li.two{list-style-type:square}
li.three{list-style-type:circle}
</style>
</head>
<body>
<h3>South Indian Kings</h3>
<ul>
<li class = "one"> Puneeth Rajkumar</li>
<li class = "two"> Mahesh Babu</li>
<li class = "three"> Suriya</li>
</ul>
</body>
</html>
Bullets in unordered lists are not limited to discs, squares, and circles. Any image
can be used in a list item bullet. Such a bullet is specified with the list-style-
image property, whose value is specified with the url form.
<html>
<head>
<title>CSS Bullets-Image</title>
<style type = "text/css">
li.image {list-style-image: url(bullet.png); font-size:25pt;}
</style>
</head>
<body>
<h1>South Indian Kings</h1>
<ul>
<li class = "image"> Puneeth Rajkumar</li>
<li class = "image"> Mahesh Babu</li>
<li class = "image"> Suriya</li>
</ul>
</body>
</html>
The following example illustrates the use of different sequence value types in nested
lists:
<html>
<head>
<title> CSS nested lists </title>
<style type = "text/css">
ol {list-style-type:upper-roman;}
ol ol {list-style-type:upper-alpha;}
ol ol ol {list-style-type:decimal;}
</style>
</head
<ol>
<li> Information Science </li>
<ol>
<li>OOMD</li>
<li>Java & J2ee</li>
<ol>
<li>classes and methods</li>
<li>exceptions</li>
<li>applets</li>
<li>servelets</li>
</ol>
<li>Computer Networks</li>
<ol>
<li>Part 1</li>
<li>Part 2</li>
</ol>
<li>DBMS</li>
<li>Operations Research</li>
</ol>
<li> Computer Science</li>
<ol>
<li>Compiler Design</li>
<li>FLAT</li>
<ol>
<li>NFA</li>
<li>DFA</li>
<li>CFG</li>
</ol>
<li>Computer Graphics</li>
<li>Artificial Intelligence</li>
</ol>
</ol>
</html>
COLOR
Color Properties:
The color property specifies the foreground color of XHTML elements. For
example, consider the following small table
<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">Strawberry</th>
</tr>
</table>
The background-color property specifies the background color of elements.
<style type=“text/css”>
P.standout {font-size:24pt;color;blue; background-color: red”>
</style>
……
<p class=“standout”>
To really make it standout ,use a red background
</p>
ALIGNMENT OF TEXT
The HTML <td> align attribute is used to set the horizontal alignment of text
content.
The text alignment property has the possible values, left (the default), center,
right, or justify.
P {text-align:right}
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.
<html>
<head> <title> The float property </title>
<style type = "text/css">
img {float: right}
</style>
The first line of the paragraph can indented using text-indent property. This
property takes either a length or a percentage values.
For example
<style type=“text/css”>
p.Indent {text-indent :0.5in}
</style>
….
<p class=“indent”>
Now is the time for web programming languages using style sheets
For all presentations
</p>
All document elements can have borders with various styles, such as color and
width. The amount of space between the content of an element and its border,
known as padding.
The space between the border and an adjacent element, known as the margin.
This model is shown in figure below.
Every element has a border-style property. It Controls whether the element has a
border and if so, the style of the border.
The styles of one of the four sides of an element can be set with
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)
bordercolor– any color.
Border color can be specified for any of the four borders (e.g., border-topcolor)
Margin:
Margin is space between the border of an element and elements neighbor.
Padding is the space between the content of an element and border.
Margin properties are named margin, which applies to all four sides of an
element, margin-left, margin-right, margin-top, margin-bottom.
Padding properties are named padding, which applies to all four sides padding-
left, padding-right, padding-top, padding-bottom.
BACKGROUND IMAGES
e.g., A section of five paragraphs for which you want some particular style It is
applied with <div> tag
Example for span tag:
<html>
<body>
<h1>The span element</h1>
<p>My mother has <span style="color:blue;font-weight:bold">blue</span> eyes and
my father has <span style="color:darkolivegreen;font-weight:bold">dark
green</span> eyes.</p>
</body>
</html>
Output:
Output:
CONFLICT RESOLUTION
Sometimes on a web page, there can be two different values for the same property on
the same element leading to conflict.
h3 {color: blue;} body h3 {color: red;}
The browser has to resolve this conflict.
There can be one or more type of conflict: i.e. when style sheets at 2 or more levels
specify different value for same property on some element.
This conflict is resolved by providing priority to the different levels of style sheets.
The inline level gets the highest priority over the document level.
The document level gets the higher priority over the external level
But the browser must be able to resolve the conflict in the first example using same
technique.
There can be several different origins of the specification of property values.
One of the value may come from a style sheet created by the author or it can be
specified by the user using the options provided by the browser.
The property values with different origin have different precedence.
The precedence can also be set for a property by marking it as important.
p.special {font-style: italic !important; font-size: 14}
This means that font-style:italic is important [this is known as weight of
specification]
The process of conflict resolution is a multi-stage sorting process.
The first step is to gather information about levels of style sheet.
Next, all the origins and weights are sorted. The following rules are considered:
o Important declarations with user origin
If there are other conflicts even after sorting, the next step is sorting by specificity.
Rules are:
o id selectors
o Class and pseudo class selectors
o Contextual selectors (more element type names means that they are
more specific)
o Universal selectors
If there still conflicts, they are resolved by giving precedence to most recently seen
specification.