It3401 Web Essentials Unit 2 Notes
It3401 Web Essentials Unit 2 Notes
It3401 Web Essentials Unit 2 Notes
UNIT – II
WEB DESIGNING
HTML – Form Elements - Input types and Media elements - CSS3 - Selectors, Box
Model, Backgrounds and Borders, Text Effects, Animations, Multiple Column
Layout, User Interface.
2.1. HTML:
HTML stands for HyperText Markup Language. Hypertext is simply a piece of text that works
as a link.
Markup Language is language of writing layout information within documents.
Basically an HTML document is a plain text file.
It contains rich text. The rich text means text with tags.
HTML is not a case sensitive language.
Any HTML program can be written in simple Notepad or WordPad text editors. The extension
to this program should be either html or htm.
This program then can be opened in some web browser and the corresponding web page can be
viewed. Let us create our first web page using HTML.
2
lOMoARcPSD|39184047
Script Explanation
1) Note that the program consists of some strings enclosed within angular brackets.
Such strings are called tags.
2) The HTML program should be written within <html> and </html>. The <html> indicates
the start of html program and </html> denotes end of html program. Use of slash (/) in the
angular bracket indicates end of that particular tag.
3) Any HTML program has two prominent parts : head and body. The head part acts as a header of a
file and contains some information like setting the title of web page.
2.1.3. Comments in HTML
The comment in HTML can be denoted as follows -
<!--It is a comment statement -->
There should not be a space between angular bracket and exclamation mark. This comment is
beginning with <!-- and ending with -->. Also note one thing that there should not be any -- inside
the comment.
2.1.4. Some Fundamental HTML Elements
In all HTML/XHTML documents the root element is <html> which has two children : head
and body.
Any text contained within the head element does not appear directly in the client area of web
browser. The head element is used for providing certain information to web browser. The <title>
element is used to give title to the web page. Note that this title does not appear in client area.
Rather it appears at the top of web browser.
The <body> element contains the information which is to be displayed in the client area of
web browser.
The body element can contain several fundamental elements such as <p>, <h1>, <div>,
<a>, <hr>, <br> and so on. The elements within the body part is for deciding the layout of your
web page.
2.1.5. Heading
There are header tags which help to display the text as some header.
The header tag is denoted by h1, h2 and so on upto h6.
3
lOMoARcPSD|39184047
Following HTML document along with its output is itself self explanatory.
HTML Document [headerDemo.html]
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1> This is a first header </h1>
<h2> This is a second header </h2>
<h3> This is a third header </h3>
<h4> This is a forth header </h4>
<h5> This is a fifth header </h5>
<h6> This is a sixth header </h6>
</body>
</html>
OUTPUT
2.1.6. Paragraphs
Following are the tags that are used for creating paragraphs
Tag Meaning
<p> This tag should be put at the end of every paragraph.
<pre> This tag is used to preserve the white spaces and lines in the text.
<div> This tag is used to make division of sections in the XHTML document.
Table 2.1. Paragraph Tags
For example
HTML Document[TextFormat.html]
<!DOCTYPE html>
<html >
4
lOMoARcPSD|39184047
<head>
</head>
<body>
<p>
Once upon a time, there was a king who kept a monkey as a pet The monkey served the king by all
the possible ways.
</p>
<div>
It was very hot in those days. So one day, when the king was sleeping, monkey was
fanning the king. Suddenly monkey noticed a fly on the chest of the king. The monkey
tried to swish it away. But fly would go away for one moment and come back again.
</div>
<div> So monkey decided to teach a lesson to the fly.</div>
<pre>
The monkey then looked for something to hit a
fly. It then found a stick.
It picked up the stick and tried to beat the fly using stick.
Hmmm at last it found a fly and
with all the force it hit the fly as a result of which the king died.
OUTPUT
5
lOMoARcPSD|39184047
</head>
<body>
<p>
Here the line breaks <br/> and new line
starts. Again line breaks<br/> Bye.
</p>
</body>
</html>
OUTPUT
6
lOMoARcPSD|39184047
Tag Purpose
<b> </b> Displays the text in bold
<i> </i> Displays the text in
italics
<strong> Displays the text in bold
</strong>
<strike> </strike> Displays the text with
strike
OUTPUT
7
lOMoARcPSD|39184047
We can align the text at left, right or at the center using a <div> tag. Here is a HTML program
which shows the text aligned left, right and centre.
HTML Document[TextAlign.html]
<!DOCTYPE html >
<html>
<head>
<title>Font Style Demo</title>
</head>
<body>
<div align="center">This line is aligned at center</div>
<div align="left">This line is aligned at left</div>
<div align="right">This line is aligned at right</div>
</body>
</html>
OUTPUT
We can set the font, size and color of the text in the web page. The tag <basefont> is used for
this purpose. The optional attributes used with <basefont> tag are as given below:
color Color value such as “red”, It displays the text with specified
“yellow” color.
and so on.
8
lOMoARcPSD|39184047
Example:
HTML Document[SetFont.html]
<!DOCTYPE html>
<html >
<head>
<title>Setting the Text </title>
</head>
<body>
<basefont face="arial" size="10">
Varsha is sweet and <br/>
Jayashree is very naughty!!<br/>
But Sachin is a serious guy<br/>
And Rashmi is a new-comer in this group
</body>
</html>
OUTPUT
HTML Document[BgColor.html]
<!DOCTYPE html>
9
lOMoARcPSD|39184047
<html>
<head>
<title>Coloring the background</title>
</head>
<body bgcolor="#FFFF00">
<h3>This document has colored background</h3>
</body>
</html>
OUTPUT
Example:
SOURCE CODE:
mainpage.html
<html>
<head></head>
<frameset rows="15%,*">
<frame src="top.html" />
<frame src="bottom.html" />
10
lOMoARcPSD|39184047
</frameset>
</html>
top.html
<html>
<body bgcolor="blue">
<font face="verdhana" size="20" color="pink">
<center><b>IT COMPUTER CENTRE</b><center>
</font>
<font color="pink">
<marquee scrolldelay="100" width="50%">(A Government approved Private Computer
centre)</marquee>
</font>
</body>
</html>
bottom.html
<html>
<head />
<frameset cols="21%,50%,*" border="2">
<frame src="col1.html" name="col1"/>
<frame src="col2.html" name="col2"/>
<frame src="col3.html" name="col3" />
</frameset>
</html
col1.html
<html>
<head>
<font color="red"><center><b>ADVERTISEMENT</b></center></font>
</head>
11
lOMoARcPSD|39184047
<body bgcolor="navy">
<br/><br/><br/>
col2.html
<html>
<head><center><font color="orange"><h1>
<marquee width="40%" behavior="alternate">WELCOME TO IT COMPUTER CENTER
!!!</marquee>
</h1></font></center>
</head>
<body bgcolor="olive">
<h2>
<ul>
<li><a href="about.html" target="col2">About Us</a> <br/><br/><br/> </li>
<li><a href="Course_Details.html" target="col2">Course Details</a> <br/><br/><br/> </li>
<li><a href="features.html" target="col2">Features</a> <br/><br/><br/></li>
<li><a href="contact.html" target="col2">Contact Us</a> <br/><br/><br/> </li>
</ul>
</h2>
</body>
</html>
about.html
<html>
12
lOMoARcPSD|39184047
course_details.html
<html>
<head><font color="blue"><h2>COUSE DETAILS</h2></font></head>
<body bgcolor="cyan">
<hr/>
The following courses are provided:-
<br/><br/><br/>
<font color="blue"><center>
<table border="2" width="60%">
<thead>
<tr><th><h3>Course</h3></th>
<th><h3>Duration</h3>(in months) </th>
</tr>
</thead>
<tbody align="left">
<tr>
13
lOMoARcPSD|39184047
<td align="center">3</td>
</tr>
<tr>
<td>R PROGRAMMING</td>
<td align="center">4</td>
</tr>
<tr>
<td align="center">3</td>
</tr>
<tr>
<td>ASP.NET / VB.NET</td>
<td align="center">3</td>
</tr>
<tr>
<td>COMPUTER SERVICING</td>
<td align="center">6</td>
</tr>
<tr>
<td>CORE JAVA</td>
<td align="center">3</td>
</tr>
<tr>
<td>J2EE</td>
lOMoARcPSD|39184047
<td align="center">6</td>
</tr>
</tbody>
</table>
</center></font>
</body>
</html>
features.html
<html>
<head><font color="blue"><h2>FEATURES</h2></font></head>
<body bgcolor="orange">
<hr/>The following features are provided by us in all coaching centres.<br/><br/>
<h3><font color="blue">
<ul>
<li> Best Classroom Teacing with best Faculty Members</li>
<li> More pratical based training</li>
<li> Online quiz, assignment, and study materials</li>
<li> Scholarship for meritorious students</li>
<li> Industry based Projects</li>
<li> Reputed certificates </li>
</ul>and more.......
</font></h3>
</body>
</html>
contact.html
<html>
15
lOMoARcPSD|39184047
<body bgcolor="cyan">
<hr/>For futher details contact us:<br/><br/><br/>
<pre><b>
Main Branch Address:<font color="blue"><h3>
NO. 100, CK Towers,
2<sup>st</sup> Floor,
MTH Road,
AVADI,
</body>
</html>
col3.html
<html>
<head />
<frameset rows="45%,*">
<frame src="login.html" />
login.html
<html>
<head><font color="YELLOW"><center>LOGIN PAGE</center></font></head>
<body bgcolor="teal">
16
lOMoARcPSD|39184047
</body>
</html>
result1.html
<head />
<body>
<h2><font color="blue"><pre>
"LOGGED IN
SUCCESSFULLY"
</pre></font></h2>
</body>
</html>
join.html
<html>
<head><font color="orange"><center><b>JOIN AS A
MEMBER</b></center></font></head>
<body bgcolor="cyan">
<pre><form method="get" action="result2.html">
Enter your Name : <input type="text" size="20"/><br>
Enter your Email-ID: <input type="text"
size="20"/><br>
Enter your Password: <input type="password" size="15"><br>
17
lOMoARcPSD|39184047
You are a:
<input type="radio" name="c1" value="School student" /> School Student
result2.html
<html>
<head />
<body>
<h2><font color="blue"><pre>
"SUBMITTED
SUCCESSFULLY"
</pre></font></h2>
</body>
</html>
18
lOMoARcPSD|39184047
new.html
<html>
19
lOMoARcPSD|39184047
An HTML form is used to collect user input. The user input is most often sent to a server for
processing.
Example:
The HTML <form> element is used to create an HTML form for user input:
The <form> element is a container for different types of input elements, such as: text fields,
checkboxes, radio buttons, submit buttons, etc.
An <input> element can be displayed in many ways, depending on the type attribute.
20
lOMoARcPSD|39184047
The <input type="text"> defines a single-line input field for text input.
Example
<html>
<body>
<form>
</form>
<p>Also note that the default width of text input fields is 20 characters.</p>
</body>
</html>
21
lOMoARcPSD|39184047
Output:
elements.
The <label> element is useful for screen-reader users, because the screen-reader will read out loud the
label when the user focus on the input element.
The <label> element also help users who have difficulty clicking on very small regions (such as radio
buttons or checkboxes) - because when the user clicks the text within the <label> element, it toggles
the radio button/checkbox.
The for attribute of the <label> tag should be equal to the id attribute of the <input> element to bind
them together.
Example:
<html>
<body>
<h2>Radio Buttons</h2>
22
lOMoARcPSD|39184047
<form>
<label for="html">HTML</label><br>
<label for="css">CSS</label><br>
<label for="javascript">JavaScript</label>
</form>
</body>
</html>
OUTPUT:
2.2.6. Checkboxes
Checkboxes let a user select ZERO or MORE options of a limited number of choices.
Example:
<html>
<body>
<h2>Checkboxes</h2>
23
lOMoARcPSD|39184047
<form action="/action_page.php">
</form>
</body>
</html>
OUTPUT:
Example:
The <input type="submit"> defines a button for submitting the form data to a form-handler.
The form-handler is typically a file on the server with a script for processing input data.
Example:
24
lOMoARcPSD|39184047
<html>
<body>
<h2>HTML Forms</h2>
<form action="/action_page.php">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page
called "/action_page.php".</p>
</body>
</html>
OUTPUT:
Notice that each input field must have a name attribute to be submitted.
If the name attribute is omitted, the value of the input field will not be sent at all.
25
lOMoARcPSD|39184047
Example:
<html>
<body>
<form action="/action_page.php">
</form>
<p>If you click the "Submit" button, the form-data will be sent to a page
called "/action_page.php".</p>
<p>Notice that the value of the "First name" field will not be submitted, because the input element
does not have a name attribute.</p>
</body>
</html>
OUTPUT:
<html>
26
lOMoARcPSD|39184047
<body>
<form action="/action_page.php">
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="fiat">Fiat</option>
<option value="audi">Audi</option>
</select>
<input type="submit">
</form>
</body>
</html>
OUTPUT:
27
lOMoARcPSD|39184047
Example:
<html>
<body>
<h2>Textarea</h2>
<form action="/action_page.php">
<br><br>
<input type="submit">
</form>
</body>
</html>
OUTPUT:
The rows attribute specifies the visible number of lines in a text area.
28
lOMoARcPSD|39184047
<html>
<body>
</body>
</html>
OUTPUT:
2.3. CSS
29
lOMoARcPSD|39184047
Each declaration includes a CSS property name and a value, separated by a colon.
Multiple CSS declarations are separated with semicolons, and declaration blocks
are surrounded by curly braces.
Example:
p{
color: red;
text-align: center;
}
Example Explained
p is a selector in CSS (it points to the HTML element you want to style: <p>).
color is a property, and red is the property value
text-align is a property, and center is the property value
Example:
<html>
<head>
<style>
body {
background-color: lightblue;
}
h1 {
color: white;
text-align: center;
}
p{
font-family: verdana;
font-size: 20px;
}
</style>
</head>
<body>
30
lOMoARcPSD|39184047
<p>This is a paragraph.</p>
</body>
</html>
OUTPUT:
1. External CSS
2. Internal CSS
3. Inline CSS
With an external style sheet, you can change the look of an entire website by changing just one file!
Each HTML page must include a reference to the external style sheet file inside the <link> element,
inside the head section.
Example:
<html>
<head>
</head>
<body>
31
lOMoARcPSD|39184047
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
An external style sheet can be written in any text editor, and must be saved with a .css extension.
The external .css file should not contain any HTML tags.
"mystyle.css"
body {
background-color: lightblue;
}
h1 {
color: navy;
margin-left: 20px;
}
OUTPUT:
An internal style sheet may be used if one single HTML page has a unique style.
32
lOMoARcPSD|39184047
The internal style is defined inside the <style> element, inside the head section.
Example:
<html>
<head>
<style>
body {
background-color: linen;
h1 {
color: maroon;
margin-left: 40px;
</style>
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
OUTPUT:
33
lOMoARcPSD|39184047
An inline style may be used to apply a unique style for a single element.
To use inline styles, add the style attribute to the relevant element. The style attribute can contain any
CSS property.
Example:
<html>
<body>
</body>
</html>
OUTPUT:
34
lOMoARcPSD|39184047
35
lOMoARcPSD|39184047
OUTPUT:
36
lOMoARcPSD|39184047
<ul>
<li>One</li>
<li>Two</li>
<li>Three</li>
</ul>
</body>
</html>
The result of loading this HTML into a browser will be as follows:
The id selector uses the id attribute of an HTML element to select a specific element.
The id of an element is unique within a page, so the id selector is used to select one unique
element! To select an element with a specific id, write a hash (#) character, followed by the id of
<html>
<head>
<style>
#para1 {
text-align: center;
color: red;
37
lOMoARcPSD|39184047
</style>
</head>
<body>
</body>
</html>
The CSS rule below will be applied to the HTML element with id="para1":
The class selector selects HTML elements with a specific class attribute.
To select elements with a specific class, write a period (.) character, followed by the class name.
Example:
<html>
<head>
<style>
38
lOMoARcPSD|39184047
.center {
text-align: center;
color: red;
</style>
</head>
<body>
</body>
</html>
In this example all HTML elements with class="center" will be red and center-aligned:
The universal selector (*) selects all HTML elements on the page.
Example:
<html>
<head>
<style>
39
lOMoARcPSD|39184047
*{
text-align: center;
color: blue;
</style>
</head>
<body>
<h1>Hello world!</h1>
<p>And me!</p>
</body>
</html>
OUTPUT:
The grouping selector selects all the HTML elements with the same style definitions.
Look at the following CSS code (the h1, h2, and p elements have the same style definitions):
40
lOMoARcPSD|39184047
Example:
<html>
<head>
<style>
h1, h2, p {
text-align: center;
color: red;
</style>
</head>
<body>
<h1>Hello World!</h1>
<h2>Smaller heading!</h2>
<p>This is a paragraph.</p>
</body>
</html>
OUTPUT:
41
lOMoARcPSD|39184047
The following example selects all <a> elements with a target attribute:
<html>
<head>
<style>
a[target] {
background-color: yellow;
}
</style>
</head>
<body>
<a href="home.html">Home</a>
<a href="about.html" target="_blank">About Us</a>
<a href="contact.html" target="_top">Contact Us</a>
</body>
</html>
OUTPUT:
42
lOMoARcPSD|39184047
2.5. CSS3:
The first implementation of CSS was drawn up in 1996, was released in 1999, and has been
supported by all browser releases since 2001. The standard for this version, CSS1, was revised
in 2008. Beginning in 1998, developers began drawing up the second specification, CSS2; its
standard was completed in 2007 and revised in 2009.
Development for the CSS3 specification commenced in 2001, with some features being
proposed as recently as 2009. Therefore, the development process will likely continue for some
time before a final recommendation for CSS3 is approved. And even though CSS3 isn’t yet
complete, people are already beginning to put forward suggestions for CSS4.
Here through the CSS3 features that have already been generally adopted by the major
browsers. Some of these features provide functionality that hitherto could be provided only
with JavaScript.
We can use CSS3 to implement dynamic features instead of JavaScript. The features
provided by CSS make document attributes part of the document itself, instead of being
tacked on through JavaScript. Making them part of the document is a cleaner design.
In CSS, the term "box model" is used when talking about design and layout.
The CSS box model is essentially a box that wraps around every HTML element. It consists of:
margins, The borders, padding, and the actual content. The image below illustrates the box model:
1. Content - The content of the box, where text and images appear
2. Padding - Clears an area around the content. The padding is transparent
3. Border - A border that goes around the padding and content
4. Margin - Clears an area outside the border. The margin is transparent
The box model allows us to add a border around elements, and to define space between elements.
43
lOMoARcPSD|39184047
The content area, bounded by the content edge, contains the "real" content of the element, such as text,
an image, or a video player. Its dimensions are the content width (or content-box width) and the
content height (or content-box height). It often has a background color or background image.
If the box-sizing property is set to content-box (default) and if the element is a block element, the
content area's size can be explicitly defined with the width, min-width, max-width, height, min-height,
and max-height properties.
The padding area, bounded by the padding edge, extends the content area to include the element's
padding. Its dimensions are the padding-box width and the padding-box height.
The border area, bounded by the border edge, extends the padding area to include the element's
borders. Its dimensions are the border-box width and the border-box height.
The thickness of the borders are determined by the border-width and shorthand border properties. If
the box-sizing property is set to border-box, the border area's size can be explicitly defined with the
width, min-width, max-width, height, min-height, and max-height properties. When there is a
background (background-color or background-image) set on a box, it extends to the outer edge of the
border (i.e. extends underneath the border in z-ordering). This default behavior can be altered with the
background-clip CSS property.
The margin area, bounded by the margin edge, extends the border area to include an empty area used
to separate the element from its neighbors. Its dimensions are the margin-box width and the margin-
box height.
The size of the margin area is determined by the margin-top, margin-right, margin-bottom, margin-
left, and shorthand margin properties. When margin collapsing occurs, the margin area is not clearly
defined since margins are shared between boxes.
Finally, note that for non-replaced inline elements, the amount of space taken up (the contribution to
the height of the line) is determined by the line-height property, even though the borders and padding
are still displayed around the content.
44
lOMoARcPSD|39184047
Example:
<html>
<head>
<style>
div {
background-color: lightgrey;
width: 300px;
margin: 20px;
</style>
</head>
<body>
<p>The CSS box model is essentially a box that wraps around every HTML element. It consists of:
borders, padding, margins, and the actual content.</p>
<div>This text is the content of the box. We have added a 50px padding, 20px margin and a 15px
green border. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea
commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu
fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt
mollit anim id est laborum.</div>
</body>
</html>
45
lOMoARcPSD|39184047
OUTPUT:
border-box
Refers to the outer edge of the border
padding-box
Refers to the outer edge of the padding area
content-box
Refers to the outer edge of the content area
46
lOMoARcPSD|39184047
states that the background may display in all parts of an element, all the way to the outer edge of the
border:
background-clip:border-box;
To keep the background from appearing within the border area of an element, you can restrict it to
only the section of an element inside the outer edge of its padding area, like this:
background-clip:padding-box;
Or to restrict the background to display only within the content area of an element, you would use
this declaration:
background-clip:content-box;
Figure 3.1. shows three rows of elements displayed in the Safari web browser, in which the first row
uses border-box for the background-clip property, the second uses padding-box, and the third uses
content-box.
In the first row, the inner box (an image file that has been loaded into the top left of the element,
with repeating disabled) is allowed to display anywhere in the element. You can also clearly see it
displayed in the border area of the first box because the border has been set to dotted.
In the second row, neither the background image nor the background shading displays in the border
area, because they have been clipped to the padding area with a background-clip property value
of padding-box.
Then, in the third row, both the background shading and the image have been clipped to display only
within the inner content area of each element (shown inside a lightcolored, dotted box), using a
background-clip property of content-box.
47
lOMoARcPSD|39184047
<style>
#example1 {
border: 10px dotted
black; padding: 15px;
background: lightblue;
background-clip: border-box;
48
lOMoARcPSD|39184047
#example2 {
#example3 {
border: 10px dotted black;
padding: 15px;
background: lightblue;
background-clip: content-box;
}
</style>
</head>
<body>
<p>The background-clip property defines how far the background should extend within an
element.</p>
49
lOMoARcPSD|39184047
<p>background-clip: padding-box:</p>
<div id="example2">
<p>background-clip: content-box:</p>
<div id="example3">
<p>The background extends to the edge of the content box.</p>
</div>
</body>
</html>
Output:
50
lOMoARcPSD|39184047
background-origin:border-box;
To set the origin of an image to the top-left outer corner of the padding area, you would use this
declaration:
background-origin:padding-box;
Or to set the origin of an image to the top-left corner of an element’s inner content section, you would
use this declaration:
background-origin:content-box;
Looking again at Figure 3.1, you can see in each row the first box uses a background-origin property
of border-box, the second uses padding-box, and the third uses content-box. Consequently, in each
row the smaller inner box displays at the top left of the border in the first box, the top left of the
padding in the second, and the top left of the content in the third box.
The only differences to note between the rows, with regard to the origins of the inner box in Figure
2.1, are that in rows two and three the inner box is clipped to the padding and content areas,
respectively; therefore, outside these areas no portion of the box is displayed.
Example:
<html>
<head>
<style>
#example1 {
border: 10px dashed black;
padding: 25px;
background: url(paper.gif);
background-repeat: no-repeat;
background-origin: padding-box;
}
#example2 {
51
lOMoARcPSD|39184047
#example3 {
border: 10px dashed black;
padding: 25px;
background: url(paper.gif);
background-repeat: no-repeat;
background-origin: content-
box;
}
</style>
</head>
<body>
<p>The background image starts from the upper left corner of the padding edge.</p>
</div>
<h2>background-origin: border-box:</h2>
<div id="example2">
<h2>Hello World</h2>
52
lOMoARcPSD|39184047
<p>The background image starts from the upper left corner of the border.</p>
53
lOMoARcPSD|39184047
</div>
<h2>background-origin: content-box:</h2>
<div id="example3">
<h2>Hello World</h2>
<p>The background image starts from the upper left corner of the content.</p>
</div>
</body>
</html>
Output:
54
lOMoARcPSD|39184047
You apply the property as follows (where ww is the width and hh is the height):
background-size:wwpx hhpx;
If you prefer, you can use only one argument, and then both dimensions will be set to that value. Also,
if you apply this property to a block-level element such as a <div> (rather than one that is inline such
as a <span>), you can specify the width and/or height as a percentage, instead of a fixed value.
If you wish to scale only one dimension of a background image, and then have the other one scale
automatically to retain the same proportions, you can use the value auto for the other dimension, like
this:
background-size:100px auto;
This sets the width to 100 pixels, and the height to a value proportionate to the increase or decrease in
width.
Different browsers may require different versions of the various background property names, so refer
to http://caniuse.com when using them to ensure you are applying all the versions required for the
browsers you are targeting.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
#example1 {
border: 2px solid
black; padding: 25px;
background: url(mountain.jpg);
background-repeat: no-repeat;
background-size: auto;
}
#example2 {
border: 2px solid
black; padding: 25px;
background: url(mountain.jpg);
background-repeat: no-repeat;
background-size: 300px
100px;
}
</style>
</head>
<body>
55
lOMoARcPSD|39184047
</div>
</body>
</html>
Output:
With CSS3 you can now attach multiple backgrounds to an element, each of which can use the
previously discussed CSS3 background properties. Figure 2.2 shows an example of this; eight different
images have been assigned to the background, to create the four corners and four edges of the
certificate border.
56
lOMoARcPSD|39184047
To display multiple background images in a single CSS declaration, separate them with commas.
Example 2.1 shows the HTML and CSS that was used to create the background in Figure 2.2
<!DOCTYPE html>
<html> <!-- backgroundimages.html -->
<head>
<title>CSS3 Multiple Backgrounds Example</title>
<style>
.border {
font-family:'Times New
Roman'; font-style :italic;
font-size :170%;
text-align :center;
padding :60px;
width :350px;
height :500px;
background :url('b1.gif') top left no-repeat,
url('b2.gif') top right no-repeat,
url('b3.gif') bottom left no-repeat,
url('b4.gif') bottom right no-repeat,
url('ba.gif') top repeat-x,
url('bb.gif') left repeat-y,
url('bc.gif') right repeat-y,
url('bd.gif') bottom repeat-x
}
</style>
</head>
<body>
<div class='border'>
<h1>Employee of the month</h1>
57
lOMoARcPSD|39184047
<h2>Awarded To:</h2>
<h3> </h3>
<h2>Date:</h2>
<h3> / / </h3>
</div>
</body>
</html>
Looking at the CSS section, you see that the first four lines of the background declaration place the
corner images into the four corners of the element, and the final four place the edge images, which are
handled last because the order of priority for background images goes from high to low. In other
words, where they overlap, additional background images will appear behind already placed images. If
the GIFs were in the reverse order, the repeating edge images would display on top of the corners,
which would be incorrect.
Using this CSS, you can resize the containing element to any dimensions and the border will always
correctly resize to fit, which is much easier than using tables or multiple elements for the same effect.
border-color:#888;
This property sets all the borders of an element to mid-gray. You can also set border colors
individually, like this (which sets the border colors to various shades of gray):
border-top-color :#000;
border-left-color :#444;
border-right-color :#888;
border-bottom-color :#ccc;
You can also set all the colors individually with a single declaration, as
This declaration sets the top border color to #f00, the right one to #0f0, the bottom one to #880, and
the left one to #00f (red, green, orange, and blue, respectively). You can also use color names for the
arguments.
Example:
<!DOCTYPE html>
<html>
58
lOMoARcPSD|39184047
<head>
<style>
h1 {
border-style: solid;
border-color:
coral;
}
div {
border-style: solid;
border-color:
coral;
}
</style>
</head>
<body>
<p><strong>Note:</strong> The border-color property does not work if it is used alone. Use
the border-style property to set the border first.</p>
</body>
</html>
Output:
59
lOMoARcPSD|39184047
60
lOMoARcPSD|39184047
</head>
<body>
<div class='box
b1'> border-
radius:40px;
</div>
<div class='box b2'>
border-radius:40px 40px 20px 20px;
</div>
<div class='box b3'>
border-top-left-radius :20px;<br>
border-top-right-radius :40px;<br>
border-bottom-left-radius :60px;<br>
border-bottom-right-radius:80px;
</div>
<div class='box b4'>
border-top-left-radius :40px
20px;<br> border-top-right-radius :40px
20px;<br> border-bottom-left-radius :20px 40px;<br>
border-bottom-right-radius:20px 40px;
</div>
</body>
</html>
61
lOMoARcPSD|39184047
So, for example, to create a rounded border with a radius of 20 pixels, you could simply
use the following declaration:
border-radius:20px;
Although most browsers will work fine with border radius properties (including IE), some current (and
many older) versions of the major browsers use different property names. So, if you wish to support
them all, you will need to also use the relevant browser-specific prefixes, such as -moz- and -webkit-.
To ensure that Example 2.2 works in all browsers, I have included all the required prefixes.
You can specify a separate radius for each of the four corners, like this (applied in a clockwise
direction starting from the top-left corner):
If you prefer, you can also address each corner of an element individually, like this:
border-top-left-radius :20px;
62
lOMoARcPSD|39184047
border-top-right-radius :40px;
border-bottom-left-radius :60px;
border-bottom-right-radius:80px;
And, when referencing individual corners, you can supply two arguments to choose a different vertical
and horizontal radius (giving more interesting and subtle borders) like this:
The first argument is the horizontal, and the second is the vertical radius.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
#example1 {
border-radius: 25px;
#example2 {
</style>
</head>
63
lOMoARcPSD|39184047
<body>
<h2>border-radius: 25px:</h2>
<div id="example1">
</div>
<div id="example2">
<p>If two values are set; the first one is for the top-left and bottom-right corner, the second one for
the top-right and bottom-left corner.</p>
</div>
</body>
</html>
Output:
64
lOMoARcPSD|39184047
The text-shadow property is similar to the box-shadow property and takes the same set of rguments: a
horizontal and vertical offset, an amount for the blurring, and the color to use. For example, the
following declaration offsets the shadow by 3 pixels both horizontally and vertically, and displays the
shadow in dark gray, with a blurring of 4 pixels:
The result of this declaration looks like Figure 2.4 , and works in all recent versions of all major
browsers (but not IE9 or lower).
Example:
<!DOCTYPE html>
<html>
<head>
<style>
h1 {
text-shadow: 2px 2px #FF0000;
}
</style>
</head>
<body>
</body>
</html>
Output:
text-overflow:ellipsis;
65
lOMoARcPSD|39184047
Without this property, when the text “To be, or not to be. That is the question.” Is truncated, the result
will look like Figure 2.5; with the declaration applied, however, the result is like Figure 2.6.
Figure 2.6. Instead of being cut off, the text trails off using an ellipsis
• The element should have an overflow property that is not visible, such as overflow:hidden.
• The element must have the white-space:nowrap property set to constrain the text.
• The width of the element must be less than that of the text to truncate.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
div.a {
white-space: nowrap;
width: 50px;
overflow: hidden;
text-overflow: clip;
border: 1px solid #000000;
}
div.b {
white-space: nowrap;
width: 50px;
overflow: hidden;
text-overflow: ellipsis;
border: 1px solid
#000000;
}
div.c {
white-space: nowrap;
width: 50px;
overflow: hidden;
text-overflow: "----";
border: 1px solid #000000;
}
</style>
66
lOMoARcPSD|39184047
</head>
<body>
<p>The following two divs contains a text that will not fit in the box.</p>
<h2>text-overflow: ellipsis:</h2>
<div class="b">Hello world!</div>
</body>
</html>
Output:
word-wrap:break-word;
67
lOMoARcPSD|39184047
For example, in Figure 20-9 the word Honorificabilitudinitatibus is too wide for the containing
box (whose righthand edge is shown as a solid vertical line between the letters t and a) and,
because no overflow properties have been applied, it has overflowed its bounds
Figure 2.7. The word is too wide for its container and has overflowed
But in Figure 2.8 the word-wrap property of the element has been assigned a value of break-word, so
the word has neatly wrapped around to the next line.
Example:
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 150px;
div.a {
word-wrap: normal;
div.b {
68
lOMoARcPSD|39184047
word-wrap: break-word;
</style>
</head>
<body>
<div class="a"> This div contains a very long word: thisisaveryveryveryveryveryverylongword. The
long word will not break and wrap to the next line.</div>
<h2>word-wrap: break-word:</h2>
<div class="b"> This div contains a very long word: thisisaveryveryveryveryveryverylongword. The
long word will break and wrap to the next line.</div>
</body>
</html>
Output:
69
lOMoARcPSD|39184047
2.10. Animations
2.10.1. Introduction:
Animation is process of making shape changes and creating motions with elements
@keyframes
animation-name
animation-duration
animation-delay
animation-iteration-count
animation-direction
animation-timing-function
animation-fill-mode
animation
<!DOCTYPE html>
<html>
<head>
70
lOMoARcPSD|39184047
<styl
e>
div {
width:
100px;
height:
100px;
background-color: red;
animation-name:
example; animation-
duration: 4s;
}
@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>
<p><b>Note:</b> When an animation is finished, it changes back to its original
style.</p>
</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).
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)).
71
lOMoARcPSD|39184047
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;}
25% {background-color: yellow;}
50% {background-color: blue;}
100% {background-color: green;}
}
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
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:
72
lOMoARcPSD|39184047
<!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>
73
lOMoARcPSD|39184047
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
The animation-delay property specifies a delay for the start of an animation. The following
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
74
lOMoARcPSD|39184047
delay: 2s;
}
@keyframes example {
left:0px; top:0px;}
}
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
75
lOMoARcPSD|39184047
<!DOCTYPE html>
<html>
<head>
<style>
div {
width: 100px;
height: 100px;
background-color: red;
position: relative;
animation-name:
example; animation-
duration: 5s;
animation-timing-function:
animation-iteration-count:
infinite; animation-direction:
alternate;
@keyframes example {
76
lOMoARcPSD|39184047
top:0px;}
</style>
</head>
<body>
<p><b>Note:</b> This example does not work in Internet Explorer 9 and earlier versions.</p>
<div></div>
</body>
</html>
77
lOMoARcPSD|39184047
1 column-count
Used to count the number of columns that element should be divided.
2 column-fill
Used to decide, how to fill the columns.
3 column-gap
Used to decide the gap between the columns.
4 column-rule
Used to specifies the number of rules.
5 rule-color
Used to specifies the column rule color.
6 rule-style
Used to specifies the style rule for column.
78
lOMoARcPSD|39184047
7 rule-width
Used to specifies the width.
8 column-span
Used to specifies the span between columns.
<html>
<head>
<style>
.multi {
/* Column count property */
-webkit-column-count: 4;
-moz-column-count: 4;
column-count: 4;
<body>
79
lOMoARcPSD|39184047
</body>
</html>
OUTPUT:
For suppose, if user wants to make text as new paper without line, we can do this by removing style
syntax as shown below –
.multi {
/* Column count property */
-webkit-column-count: 4;
-moz-column-count: 4;
OUTPUT:
column-count: 4;
80
lOMoARcPSD|39184047
Used to move down when you have pressed on down arrow button in keypad.
7 nav-left
Used to move left when you have pressed on left arrow button in keypad.
8 nav-right
Used to move right when you have pressed on right arrow button in keypad.
9 nav-up
81
lOMoARcPSD|39184047
Table 2.6. CSS3 User Interface Property value & its Description
horizontal
vertical
both
Using of both value in resize property in css3 user interface −
Output:
<html>
<head>
<styl
e>
div
{
border: 2px
solid; padding:
2.12.2. CSS3
20px;Outline
width: offset:
300px; resize:
Out line both;
meansoverflow:
draw a line around the element at outside of border.
auto;
}
</style>
<html>
</head>
<body>
82
lOMoARcPSD|39184047
<head>
<styl
e>
div
{
margin:
20px;
padding:
10px; width:
300px;
height:
100px;
border: 5px solid
pink; outline: 5px
solid green; outline-
offset: 15px;
}
</style>
OUTPUT:
83