Wdm-Unit-2 Notes
Wdm-Unit-2 Notes
Wdm-Unit-2 Notes
background-color: orange
}
Note that .orange doesn't mean anything special - you can use anything as a class name
provided that it starts with a period and is composed of a single word (spaces and underscores
are not allowed).
To apply a class to an HTML tag, you use the the class attribute (which was introduced
in HTML 4.0). For example, to highlight important text on your page, apply the above style to
a <p> tag...
<p class="orange">Cascading Style Sheets</p>
Note that the period before the class name is not included.
How to use style sheets?
2
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
A:hover {color:red}
-->
</style>
</head>
While this method is better than applying styles on a tag-by-tag basis, it still ties the
style to a particular HTML document.
Eg. 1.
<?xml version = "1.0"?>
<html >
<head> <title>Embedded Style Sheets</title>
<style type = "text/css">
em { background-color: #8000ff;
color: white }
h1 { font-family: arial, sans-serif }
p { font-size: 14pt }
.special { color: blue }
</style>
</head>
<body>
<!-- this class attribute applies the .special style -->
<h1 class = "special"> Welcome to India </h1>
<p class = "special"> The IT company's clients include many
<em>Fortune 1000 companies</em>, government agencies,
branches of the military and business organizations.
</p>
</body>
</html>
Note :
Relative Values of font-size properties are : xx-small,x-small,small,smaller,
medium, large, larger, x-large and xx-large.
Parent element or ancestor element – allow to access the values for child element.
Child or descendent element – inherits the style from the parent element. (i.e.Nested
element)
3
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
4
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
5
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
6
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
<p>
Hello World!
</p>
</body>
</html>
Output :
Explanation :
<link rel="stylesheet" > is known as link element associates style sheet with doc.
type="text/css" - type attribute specifies style language used .
href="style2.css – Provides style sheet URL.
title="Style 2" – This attribute provides style sheet name.
2.2. Cascading Style Sheet Features :
◼ It can be used to separate the presentation of information from the information content
and semantic tagging.
◼ Advantages
✓ Allow the information in the document to be presented without change
in a variety of ways.
✓ It’s relatively easy to give all of the elements on a page a consistent
appearance.
✓ Both the document author and the person viewing the document can
specify aspects of the document style as it is displayed by the browser.
2.3. Core Syntax :
7
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
A CSS style sheet consists of one or more style rules (sometimes called statements).
This form of rule is called a ruleset and consists of two parts: a selector string followed by a
declaration block, which is enclosed in curly braces ({ and }).
That is a CSS rule has two main parts: a selector, and one or more declarations.
The declaration block contains a list (possibly empty) of declarations separated by
semicolons (;) (the final declaration can also be followed by a semicolon, and many style sheet
authors follow this convention).
The selector string indicates the elements to which the rule should apply, and each
declaration within the declaration block specifies a value for one style property of those
elements.
The selector is normally the HTML element you want to style.
Each declaration consists of a property and a value. The property is the style attribute
you want to change. Each property has a value.
* { font-weight:bold }
Specific elements by id: /* Elements with certain id's have light background */
#p1, #p3 { background-color:aqua }
Elements belonging to a style class:
/* Elements in certain classes are italic, large font, or both */
Another HTML attribute that is frequently used with style sheets is class. This
attribute is used to associate style properties with an element as follows. First, the style
sheet must contain one or more rulesets having class selectors, which are selectors that
are preceded by a period (.), such as .takeNote in the rule
#p4, .takeNote { font-style:italic }
Where . takeNote - class selector: begins with a period .
Elements of a certain type and class:
ID and class selectors can also be prefixed by an element type name, which
restricts the selector to elements of the specified type. For example, the style rule
span.special { font-size:x-large }
- this rule applies only to span elements that have a class value of special.
• Referencing a style class in HTML:
< span class =”takeNote special cool”>
Source anchor elements:
In addition to ID and class selectors, several predefined pseudo-classes are
associated with a (anchor) elements that have an href attribute (source anchors).
9
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
a:active { color:red }
Where a: link, a: visited , a:hover , a:active are pseudo classes
Element types that are descendants:
ul span { font-variant:small-caps }
ul ol li { letter-spacing:1em }
where
li - rule applies to li element that is
ol - part of the content of an ol element
ul - that is part of the content of a ul element
In the preceding style rule, each of the selectors (comma-separated components of the
selector string) was simply the name of an element type. This form of selector is called a type
selector. Several other forms of selector are also defined in CSS. One is the universal selector,
which is denoted by an asterisk (*). The universal selector represents every possible element
type. So, for example, the rule
* { font-weight:bold }
This specifies a value of bold for the font-weight property of every element in the
document.
Another form of selector is the ID selector. Recall that every element in an XHTML
document has an associated id attribute, and that if a value is assigned to the id attribute for an
element then no other element’s id can be assigned the same value. If a selector is preceded by
a number sign (#), then it represents an id value rather than an element type name. For example
,
<p id="p3">
...
</p>
then the following rule will cause this paragraph (and another element with id value p1, if such
an element exists) to be displayed with an aqua background:
#p1, #p3 { background-color:aqua }
Note that id values are case-sensitive, so this rule will not apply to an element that has an id
value of P1.
Example program for selector,
<!DOCTYPE html
10
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
11
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
</body>
</html>
The above programs shows HTML document used to demonstrate various types of CSS
selectors.
Output :
At-Rules :
The other form of rule is called an at-rule. The only at-rule that is widely supported
and used at the time of this writing is the rule beginning with @import. This rule is used to
input one style sheet file into another one.
For example, a style sheet such as
@import url("general-rules.css");
h1, h2 { background-color: aqua }
12
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
will first read in rules from the file general-rules.css before continuing with the other rule in
this style sheet. The url() function is used to mark its string argument as a URL. Single quotes
can be used for this argument rather than double quotes; in fact, the quotes are not required at
all. The URL can be absolute or relative. If it is a relative URL, like the one.
The @import rule must end with a semicolon, as shown. Also, all @import rules must
appear at the beginning of a style sheet, before any rule set statements.
2. FORMATTING TEXT
Text Properties :
Specifically, we will learn about how to select a font and how to modify text properties
such as color. The text properties are ,
❖ Font-family font- family:'Jenkins v2.0 ";
❖ Font-size font-size : 12pt; (in,cm,px..)
❖ Font-style font-style : italic; (normal)
❖ Font-weight font-weight :bold; (normal)
❖ Text color color: #000000; (black)
Font Families :
A font family is a collection of related fonts, and a font is a mapping from a character
(Unicode Standard code point) to a visual representation of the character (a glyph). Each glyph
is drawn relative to a rectangular character cell (also known as the character’s content area),
which is shown shaded for each character in the figure.
The fonts within a font family differ from one another in attributes such as boldness or
degree of slantedness, but they all share a common design. The font families used in this
example are, in order of use, Jenkins v2.0, Times New Roman R _ , Jokewood, and Helvetica
,etc.
The font family to be used for displaying text within an HTML element is specified
using the font-family style property. For example, the start tag
<p style="font-family:'Jenkins v2.0'">
Instead, a recommended mechanism for specifying a font family in CSS is to use a comma-
separated list of font families as the value of the font-family property or font-family property
can accept a list of families, including generic font families such as
font-family:"Edwardian Script ITC","French Script MT",cursive
13
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
14
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
15
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
Third, the font-size specification may be given using what is termed an absolute size
keyword. One of these keywords is medium, the initial value for font-size. The remaining
keywords are xx-small, x-small, small, large, x-large, and xx-large.
Finally, the relative size keywords smaller and larger may be specified.
CSS also provides several other font style properties; three of the most commonly used
are shown in following table,
The fig. Shows A box representing a p element that consists of two line boxes, each
partially filled with character cells.
Character cells representing the text are placed side by side in the topmost line box until
it contains as many words (strings of contiguous non-white-space characters) as possible; a
single space (with width defined by the font) separates each word.
Height of line box given by line-height
◼ Initial value: normal (i.e., cell height; relationship with em height is font-
specific)
◼ Other values (following are equivalent):
Thus, the following declarations are all equivalent in terms of their effect on the p element
itself:
16
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
line-height:1.5em
line-height:150%
line-height:1.5
When line-height is greater than cell height
Inheritance of line-height:
◼ Specified value if normal or unit-less number
◼ Computed value otherwise
Font shortcut property:
A CSS shortcut property, which is a property that allows values to be specified
for several nonshorthand properties with a single declaration. As an example of the
use of the font shortcut, the declaration block
{ font: italic bold 12pt "Helvetica",sans-serif }
is equivalent to the the declaration block
{ font-style: italic;
font-variant: normal;
font-weight: bold;
font-size: 12pt;
line-height: normal;
font-family: "Helvetica",sans-serif }
Notice that the font shortcut always affects all six of the properties shown.
Text Formatting and Color :
Several other CSS properties can affect the appearance of text. These are listed in Table.
All of these properties except text-decoration are inherited. And, while not inherited, text-
decoration automatically applies to all text within the element, while skipping nontext, such as
images.
17
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
18
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
◼ Color name: black, gray, silver, white, red, lime, blue, yellow, aqua, fuchsia,
maroon, green, navy, olive, teal, purple,etc.
◼ red/green/blue (RGB) values
19
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
Padding:
Padding clears the area inside the border of the element. It introduces extra space between the
boundary and the content of the element. Just like the margin property, padding has a
shorthand property that sets the padding for all the four sides. It can also be set individually.
Syntax:
Where each padding value is either a length, percentage value, auto, or inherit from the parent
element.A padding of 40px, padding:40px; means an extra space of 40px will be added
around the content of the element on all the sides.
padding properties are used to generate space around an element's content, inside of any
defined borders.With CSS, you have full control over the padding. There are properties for
setting the padding for each side of an element (top, right, bottom, and left).
CSS has properties for specifying the padding for each side of an element:
inherit - specifies that the padding should be inherited from the parent element
Example
div {
padding-top: 50px;
padding-right: 30px;
padding-bottom: 50px;
20
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
padding-left: 80px;
}
An element's padding is the space between its content and its border.
padding:10px 5px;
padding:10px;
21
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
The CSS width property specifies the width of the element's content area. The content area is
the portion inside the padding, border, and margin of an element (the box model).So, if an
element has a specified width, the padding added to that element will be added to the total
width of the element. This is often an undesirable result.
Example
Here, the <div> element is given a width of 300px. However, the actual width of the <div>
element will be 350px (300px + 25px of left padding + 25px of right padding):
div {
width: 300px;
padding: 25px;
}
To keep the width at 300px, no matter the amount of padding, you can use the box-
sizing property. This causes the element to maintain its actual width; if you increase the
padding, the available content space will decrease.
Example
Use the box-sizing property to keep the width at 300px, no matter the amount of padding:
div {
width: 300px;
padding: 25px;
box-sizing: border-box;
}
The padding property in CSS defines the innermost portion of the box model, creating space
around an element’s content, inside of any defined margins and/or borders.
22
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
23
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
The above Figure also gives the CSS property names corresponding to the 12 distances
between adjacent edges in the box model. Notice that the border properties have the suffix -
width. This suffix is used to distinguish border properties related to distances from other border
properties that affect the color and style of borders (and have the suffixes –color and -style,
respectively). Note that the same suffix is used for both horizontal and vertical distances, which
can be confusing, since in the rest of the box model “width” normally refers to a horizontal
distance.
For example , The following HTML document demonstrating basic box model style properties.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>
SpanBoxStyle.html
</title>
<link rel="stylesheet" type="text/css" href="span-box-style.css" />
</head>
<body>
<p>
The <span>first span</span> and <span>second span</span>.
</p>
</body>
</html>
/* span-box-style.css */
/* solid is a border style (as opposed to dashed, say). */
span { margin-left: 1cm;
border-left-width: 10px;
border-left-color: silver;
border-left-style: solid;
padding-left: 0.5cm;
border-right-width: 5px;
border-right-color: silver;
border-right-style: solid }
24
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
Output :
Table shows Basic CSS Style Properties Associated with the Box Model
25
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
Table shows Meaning of Values for Certain Shorthand Properties that Take One to Four Values
As another example, the style declaration
margin: 15px 45px 30px
is equivalent to
margin-top: 15px
margin-right: 45px
margin-left: 45px
margin-bottom: 30px
There is no precise definition for most of these border styles, so their visual appearance
may vary somewhat when displayed in different browsers.For example,
/* border-styles.css */
#p1 {
background-color: yellow;
border: 6px maroon;
border-style: solid dashed dotted double
}
#p2 {
border: 16px teal;
border-style: groove ridge inset outset
}
Finally, you probably have noticed that shorthand properties make it possible to declare
multiple values for a single property within a single declaration block. For example, the value
of border-top-style can be specified by a direct declaration of this property as well as by
declarations for the border-top and border shorthand properties.
So, for example, in the declaration block
{ border: 15px solid;
26
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
Border property
The CSS border properties allow you to specify the style and color of an element’s border.
border-width
The border-width property is used to set the width of the border. The width is set in pixels, or
by using one of the three pre-defined values: thin, medium, or thick.
border-color
The border-color property is used to set the color of the border. The color can be set by:
1 div.div-2{
2 border:1px solid #ccc;
3 }
27
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
Margin property
The CSS margin properties define the space around elements. The margin clears an area
around an element (outside the border). The margin does not have a background color, and is
completely transparent.
You can define the element margin values the following way:
• margin-top:100px;
• margin-bottom:100px;
• margin-right:50px;
• margin-left:50px;
You can also use the shortand property:
• margin:25px 50px;
o top and bottom margins are 25px
o right and left margins are 50px
• margin:25px;
o all four margins are 25px
Using the auto value for the margin property you can center the block horizontally.
1 div.div-3{
2 margin: 0 auto;
3 }
28
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
and absolute to represent the respective flow positionings, or fixed, which is a special type of
absolute positioning discussed in the exercises. The float property can be set for elements with
either static or relative specified for position. Possible values for float are none (the initial
value), left, or right.
Any element with a position value other than static is said to be positioned. If the
position value of a positioned element is absolute or fixed, then it is said to be absolutely
positioned; otherwise it is relatively positioned. Four (noninherited) properties apply
specifically to positioned elements: left, right, top, and bottom. Each of these properties takes
a value that is either a length, a percentage, or the keyword auto (the initial value).
Relative Positioning :
Relative positioning is useful when you want to nudge a box a bit from the position
where the browser would normally render it, and you want to do so without disturbing the
placement of any other boxes. That is, all other boxes are positioned as if the nudged box had
never moved.
The following FIGURE demonstrate the HTML document using relative positioning
to nudge text to the left.
Notice that the first letter of each of the words “Red,” “Yellow,” and “Green” has a
background that is partly shaded and partly not.
we use a style rule
.right { position:relative; right:0.25em }
Notice that for relatively positioned boxes, a positive value for the right property moves
the box to the left by the specified amount.
Alternatively, if the style rule had been
.right { position:relative; left:-0.25em }
Float Positioning :
Float positioning is often used when embedding images within a paragraph. For
example, recall that the HTML markup,
<p>
<img
29
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
src="http://www.w3.org/Icons/valid-xhtml10"
alt="Valid XHTML 1.0!" height="31" width="88"
style="float:right" />
See
<a href="http://www.w3.org/TR/html4/index/elements.html">the
W3C HTML 4.01 Element Index</a>
for a complete list of elements.
</p>
Line boxes below the floated box extend to the full width of the containing block,
producing a visual effect of text wrapping around the floated block.
30
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
▪ Absolute positioning offers total control over the placement of boxes on the
canvas.
▪ Specify location for corner of box relative to positioned containing block
we will use the style rule
p { position:relative; margin-left:10em }
▪ Specify location for edges of box relative to positioned containing block
The rule is
.marginNote { position:absolute;
top:0; left:-10em; width:8em;
background-color:yellow }
Absolutely positioned box does not affect positioning of other boxes!
31
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
Header
A header is usually located at the top of the website (or right below a top navigation menu). It
often contains a logo or the website name:
Example
32
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
.header {
background-color: #F1F1F1;
text-align: center;
padding: 20px;
}
Result
Header
Navigation Bar
A navigation bar contains a list of links to help visitors navigating through your website:
Example
/* The navbar container */
.topnav {
overflow: hidden;
background-color: #333;
}
/* Navbar links */
.topnav a {
float: left;
display: block;
color: #f2f2f2;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}
Result
The layout in this section, often depends on the target users. The most common layout is one
(or combining them) of the following:
1-column:
2-column:
3-column:
We will create a 3-column layout, and change it to a 1-column layout on smaller screens:
Example
/* Create three equal columns that float next to each other */
.column {
float: left;
width: 33.33%;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to
each other on smaller screens (600px wide or less) */
@media screen and (max-width: 600px) {
.column {
width: 100%;
}
}
Result
Column
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sit amet pretium urna.
Vivamus venenatis velit nec neque ultricies, eget elementum magna tristique.
Column
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sit amet pretium urna.
Vivamus venenatis velit nec neque ultricies, eget elementum magna tristique.
Column
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sit amet pretium urna.
Vivamus venenatis velit nec neque ultricies, eget elementum magna tristique.
34
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
Unequal Columns
The main content is the biggest and the most important part of your site.
It is common with unequal column widths, so that most of the space is reserved for the main
content. The side content (if any) is often used as an alternative navigation or to specify
information relevant to the main content. Change the widths as you like, only remember that
it should add up to 100% in total:
Example
.column {
float: left;
}
/* Middle column */
.column.middle {
width: 50%;
}
/* Responsive layout - makes the three columns stack on top of each other instead of next to
each other */
@media screen and (max-width: 600px) {
.column.side, .column.middle {
width: 100%;
}
}
Result
Side
Main Content
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas sit amet pretium urna.
Vivamus venenatis velit nec neque ultricies, eget elementum magna tristique. Quisque
vehicula, risus eget aliquam placerat, purus leo tincidunt eros, eget luctus quam orci in velit.
Praesent scelerisque tortor sed accumsan convallis.
Side
35
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
Footer
The footer is placed at the bottom of your page. It often contains information like copyright
and contact info:
Example
.footer {
background-color: #F1F1F1;
text-align: center;
padding: 10px;
}
Result
Footer
36
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
div {
width: 100px;
height: 100px;
background: red;
transition: width 2s;
}
The transition effect will start when the specified CSS property (width) changes
value.
Now, let us specify a new value for the width property when a user mouses over the
<div> element:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
transition: width 2s;
}
div:hover {
width: 300px;
}
</style>
</head>
<body>
<h1>The transition Property</h1>
<p>Hover over the div element below, to see the transition effect:</p>
<div></div>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier
versions.</p>
</body>
</html>
37
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
Notice that when the cursor mouses out of the element, it will gradually change back to its
original style.
Change Several Property Values
The following example adds a transition effect for both the width and height property, with a
duration of 2 seconds for the width and 4 seconds for the height:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
transition: width 2s, height 4s;
}
div:hover {
width: 300px;
height: 300px;
}
</style>
38
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
</head>
<body>
<h1>The transition Property</h1>
<p>Hover over the div element below, to see the transition effect:</p>
<div></div>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier
versions.</p>
</body>
</html>
OUTPUT:
The transition-timing-function property specifies the speed curve of the transition effect.
• ease - specifies a transition effect with a slow start, then fast, then end slowly (this is
default)
• linear example shows some of the d- specifies a transition effect with the same speed from
start to end
<!DOCTYPE html>
39
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
div:hover {
width: 300px;
</style>
</head>
<body>
<p>Hover over the div elements below, to see the different speed curves:</p>
<div id="div1">linear</div><br>
<div id="div2">ease</div><br>
<div id="div3">ease-in</div><br>
<div id="div4">ease-out</div><br>
<div id="div5">ease-in-out</div><br>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
</body>
</html>
40
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
OUTPUT:
The transition-delay property specifies a delay (in seconds) for the transition effect.
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
transition-delay: 1s;
div:hover {
width: 300px;
41
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
</style>
</head>
<body>
<p>Hover over the div element below, to see the transition effect:</p>
<div></div>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
</body>
</html>
Transition + Transformation:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
42
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
div:hover {
width: 300px;
height: 300px;
transform: rotate(180deg);
</style>
</head>
</head>
<body>
<h1>Transition + Transform</h1>
<div></div>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
</body>
</html>
The CSS transition properties can be specified one by one, like this:
<!DOCTYPE html>
<html>
<head>
<style>
43
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
div {
width: 100px;
height: 100px;
background: red;
transition-property: width;
transition-duration: 2s;
transition-timing-function: linear;
transition-delay: 1s;
div:hover {
width: 300px;
</style>
</head>
</html>
<body>
<p>Hover over the div element below, to see the transition effect:</p>
<div></div>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
</body>
</html>
44
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background: red;
div:hover {
width: 300px;
</style>
</head>
<body>
<p>Hover over the div element below, to see the transition effect:</p>
<div></div>
45
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
</body>
</html>
TRANSFORM PROPERTY:
A)CSS 2D Transforms
CSS transforms allow you to move, rotate, scale, and skew elements.
With the CSS transform property you can use the following 2D transformation methods:
• translate()
• rotate()
• scaleX()
• scaleY()
• scale()
• skewX()
• skewY()
• skew()
46
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
• matrix()
• The translate() method moves an element from its current position (according to
the parameters given for the X-axis and the Y-axis).
• The following example moves the <div> element 50 pixels to the right, and 100
pixels down from its current position:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
border: 1px solid black;
-ms-transform: translate(50px,100px); /* IE 9 */
transform: translate(50px,100px); /* Standard syntax */
}
</style>
</head>
<body>
<div>
This div element is moved 50 pixels to the right, and 100 pixels down from its
current position.
</div>
</body>
</html>
47
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
The following example rotates the <div> element clockwise with 20 degrees:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
div#myDiv {
-ms-transform: rotate(20deg); /* IE 9 */
</style>
</head>
<body>
48
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
<div>
</div>
<div id="myDiv">
</div>
</body>
</html>
49
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
The scale() method increases or decreases the size of an element (according to the
parameters given for the width and height).
The following example increases the <div> element to be two times of its original width,
and three times of its original height:
<!DOCTYPE html>
<html>
<head>
<style>
div {
margin: 150px;
width: 200px;
height: 100px;
background-color: yellow;
-ms-transform: scale(2,3); /* IE 9 */
</style>
</head>
<body>
<div>
This div element is two times of its original width, and three times of its original height.
</div>
50
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
</body>
</html>
B)CSS 3D Transforms:
CSS also supports 3D transformations.
Mouse over the elements below to see the difference between a 2D and a 3D transformation:
• rotateX()
• rotateY()
• rotateZ()
The rotateX() method rotates an element around its X-axis at a given degree:
51
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
#myDiv {
transform: rotateX(150deg);
</style>
</head>
<body>
<p>The rotateX() method rotates an element around its X-axis at a given degree.</p>
<div>
</div>
<div id="myDiv">
</div>
52
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
<p><b>Note:</b> Internet Explorer 9 (and earlier versions) does not support the rotateX()
method.</p>
</body>
</html>
The rotateY() method rotates an element around its Y-axis at a given degree:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
53
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
height: 100px;
background-color: yellow;
#myDiv {
transform: rotateY(150deg);
</style>
</head>
<body>
<p>The rotateY() method rotates an element around its Y-axis at a given degree.</p>
<div>
</div>
<div id="myDiv">
</div>
<p><b>Note:</b> Internet Explorer 9 (and earlier versions) does not support the rotateY() method.</p>
</body>
</html>
54
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
background-color: yellow;
#myDiv {
transform: rotateY(150deg);
</style>
</head>
<body>
<p>The rotateY() method rotates an element around its Y-axis at a given degree.</p>
<div>
55
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
</div>
<div id="myDiv">
</div>
<p><b>Note:</b> Internet Explorer 9 (and earlier versions) does not support the rotateY() method.</p>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 300px;
height: 100px;
56
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
background-color: yellow;
#myDiv {
transform: rotateZ(90deg);
</style>
</head>
<body>
<p>The rotateZ() method rotates an element around its Z-axis at a given degree.</p>
<div>
</div>
<div id="myDiv">
</div>
<p><b>Note:</b> Internet Explorer 9 (and earlier versions) does not support the rotateZ() method.</p>
</body>
</html>
This property allows you to rotate, scale, move, skew, etc., elements.
ANIMATION PROPERTY
- allows animation of HTML elements without using JavaScript or Flash!
57
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
• @keyframes
• animation-name
• animation-duration
• animation-delay
• animation-iteration-count
• animation-direction
• animation-timing-function
• animation-fill-mode
• animation
@keyframes example {
from {background-color: red;}
to {background-color: yellow;}
}
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
Note: The animation-duration property defines how long an animation should take to complete. If the animation-
duration property is not specified, no animation will occur, because the default value is 0s (0 seconds).
58
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
In the example above we have specified when the style will change by using the keywords "from" and "to"
(which represents 0% (start) and 100% (complete)).
It is also possible to use percent. By using percent, you can add as many style changes as you like.
The following example will change the background-color of the <div> element when the animation is 25%
complete, 50% complete, and again when the animation is 100% complete:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
animation-name: example;
animation-duration: 4s;
@keyframes example {
0% {background-color: red;}
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
59
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
The following example will change both the background-color and the position of the
<div> element when the animation is 25% complete, 50% complete, and again when
the animation is 100% complete:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation-name: example;
animation-duration: 4s;
@keyframes example {
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
60
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
Delay an Animation:
The following example has a 2 seconds delay before starting the animation:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation-name: example;
animation-duration: 4s;
animation-delay: 2s;
@keyframes example {
</style>
</head>
<body>
61
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation-name: example;
animation-duration: 5s;
animation-timing-function: linear;
animation-delay: 2s;
animation-iteration-count: infinite;
animation-direction: alternate;
@keyframes example {
62
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
JAVASCRIPT:
JavaScript is used to create interactive websites. It is mainly used for:
63
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
o Client-side validation,
o Displaying pop-up windows and dialog boxes (like an alert dialog box, confirm dialog box
JavaScript Example
<script>
</script>
<script>
var a=10;
var b=20;
</script>
It is represented by forward slash with asterisk then asterisk with forward slash. For example:
<script>
/* It is multi line comment.
It will not be displayed */
document.write("example of javascript multiline comment");
</script>
64
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
JavaScript Variable:
A JavaScript variable is simply a name of storage location. There are two types of
variables in JavaScript : local variable and global variable.
There are some rules while declaring a JavaScript variable (also known as
identifiers).
2. After first letter we can use digits (0 to 9), for example value1.
3. JavaScript variables are case sensitive, for example x and X are different
variables.
<script>
var x = 10;
var y = 20;
var z=x+y;
document.write(z);
</script>
<script>
function abc(){
var x=10;//local variable
}
</script>
Or,
<script>
If(10<13){
65
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
<script>
var data=200;//gloabal variable
function a(){
document.writeln(data);
}
function b(){
document.writeln(data);
}
a();//calling JavaScript function
b();
</script>
JavaScript Operators:
JavaScript operators are symbols that are used to perform operations on operands.
For example:
1. var sum=10+20;
1. Arithmetic Operators
3. Bitwise Operators
4. Logical Operators
5. Assignment Operators
66
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
6. Special Operators
JavaScript If-else:
The JavaScript if-else statement is used to execute the code whether condition is
true or false. There are three forms of if statement in JavaScript.
1. If Statement
2. If else statement
3. if else if statement
if(expression){
//content to be evaluated
}
<script>
var a=20;
if(a>10){
document.write("value of a is greater than 10");
}
</script>
<script>
var a=20;
if(a%2==0){
document.write("a is even number");
}
else{
document.write("a is odd number");
}
</script>
<script>
var grade='B';
var result;
67
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
switch(grade){
case 'A':
result="A Grade";
break;
case 'B':
result="B Grade";
break;
case 'C':
result="C Grade";
break;
default:
result="No Grade";
}
document.write(result);
</script>
JavaScript Loops:
The JavaScript loops are used to iterate the piece of code using for, while, do
while or for-in loops. It makes the code compact. It is mostly used in array.
1. for loop
2. while loop
3. do-while loop
4. for-in loop
<script>
for (i=1; i<=5; i++)
68
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
{
document.write(i + "<br/>")
}
</script>
While loop
while (condition)
{
code to be executed
}
<script>
var i=11;
while (i<=15)
{
document.write(i + "<br/>");
i++;
}
</script>
do{
code to be executed
}while (condition);
<script>
var i=21;
do{
document.write(i + "<br/>");
i++;
}while (i<=25);
</script>
69
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
JavaScript Functions
JavaScript functions are used to perform operations. We can call JavaScript
function many times to reuse the code.
Less coding: It makes our program compact. We don’t need to write many lines
of code each time to perform a common task.
1.<script>
function msg(){
alert("hello! this is message");
}
</script>
<input type="button" onclick="msg()" value="call function"/>
2. <script>
function getcube(number){
alert(number*number*number);
}
</script>
<form>
<input type="button" value="click" onclick="getcube(4)"/>
</form>
70
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
Dialog Boxes :
• alert(message) - Displays an alert box with a message defined by the string message.
Example:
alert("An error occurred!")
• confirm(message) - When called, it will display the message and two boxes. One box
is "OK" and the other is "Cancel". If OK is selected, a value of true is returned,
otherwise a value of false is returned. An example:
if (confirm("Select OK to continue, Cancel to abort"))
{
document.write("Continuing")
}
else
{
document.write("Operation Canceled")
}
• prompt(message) - Displays a box with the message passed to the function displayed.
The user can then enter text in the prompt field, and choose OK or Cancel. If the user
chooses Cancel, a NULL value is returned. If the user chooses OK, the string value
entered in the field is returned.
An example: // Dynamic Welcome Page
var response=prompt("Enter your name")
if (response != null)
{
document.write(response)
}
71
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
JavaScript Events
The change in the state of an object is known as an Event. In html, there are
various events which represents that some activity is performed by the user or by
the browser.
This process of reacting over the events is called Event Handling. Thus, js handles
the HTML events via Event Handlers.
For example, when a user clicks over the browser, add js code, which will execute
the task to be performed on the event.
➢ A mouse click
➢ The web page loading
➢ Mousing over a hot spot on the web page, also known as hovering
➢ Selecting an input box in an HTML form
➢ A keystroke
Click Event
<html>
<head> Javascript Events </head>
<body>
<script language="Javascript" type="text/Javascript">
<!--
function clickevent()
{
document.write("This is JavaTpoint");
}
//-->
</script>
<form>
<input type="button" onclick="clickevent()" value="Who's this?"/>
</form>
</body>
</html>
72
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
MouseOver Event
<html>
<head>
<h1> Javascript Events </h1>
</head>
<body>
<script language="Javascript" type="text/Javascript">
<!--
function mouseoverevent()
{
alert("This is JavaTpoint");
}
//-->
</script>
<p onmouseover="mouseoverevent()"> Keep cursor over me</p>
</body>
</html>
Focus Event
<html>
<head> Javascript Events</head>
<body>
<h2> Enter something here</h2>
<input type="text" id="input1" onfocus="focusevent()"/>
<script>
<!--
function focusevent()
{
document.getElementById("input1").style.background=" aqua";
}
//-->
</script>
</body>
</html>
73
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
Load event
<html>
<head>Javascript Events</head>
</br>
<body onload="window.alert('Page successfully loaded');">
<script>
<!--
document.write("The page is loaded successfully");
//-->
</script>
</body>
</html>
JavaScript Form
Login Form
<html>
<head>
<title> Login Form</title>
</head>
<body>
<h3> LOGIN </h3>
<formform ="Login_form" onsubmit="submit_form()">
<h4> USERNAME</h4>
<input type="text" placeholder="Enter your email id"/>
<h4> PASSWORD</h4>
<input type="password" placeholder="Enter your password"/></br></br>
<input type="submit" value="Login"/>
<input type="button" value="SignUp" onClick="create()"/>
</form>
<script type="text/javascript">
function submit_form(){
alert("Login successfully");
}
function create(){
window.location="signup.html";
74
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
}
</script>
</body>
</html>
SignUp Form
<html>
<head>
<title> SignUp Page</title>
</head>
<body align="center" >
<h1> CREATE YOUR ACCOUNT</h1>
<table cellspacing="2" align="center" cellpadding="8" border="0">
<tr><td> Name</td>
<td><input type="text" placeholder="Enter your name" id="n1"></td></tr>
<tr><td>Email </td>
<td><input type="text" placeholder="Enter your email id" id="e1"></td></tr>
<tr><td> Set Password</td>
<td><input type="password" placeholder="Set a password" id="p1"></td></tr>
<tr><td>Confirm Password</td>
<td><input type="password" placeholder="Confirm your password" id="p2"></td>
</tr>
<tr><td>
<input type="submit" value="Create" onClick="create_account()"/>
</table>
<script type="text/javascript">
function create_account(){
var n=document.getElementById("n1").value;
var e=document.getElementById("e1").value;
var p=document.getElementById("p1").value;
var cp=document.getElementById("p2").value;
//Code for password validation
var letters = /^[A-Za-z]+$/;
75
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
76
IT8078- WEB DESIGN AND MANAGEMENT-UNIT-2-IV YEAR IT-PIT
77