Unit 3 Web Design and Development
Unit 3 Web Design and Development
UNIT III:
CSS
1
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
USES OF CSS
o CSS Stands for "Cascading Style Sheet." Cascading style sheets are
used to format the layout of Web pages.
o They can be used to define text styles, table sizes, and other aspects of
Web pages that previously could only be defined in a page's HTML,
o CSS are a powerful way to separate content from design in our Web
Forms applications.
o CSS helps Web developers create a uniform look across several pages
of a Web site.
o Instead of defining the style of each table and each block of text
within a page's HTML, commonly used styles need to be defined only
once in a CSS document.
o Once the style is defined in cascading style sheet, it can be used by
any page that references the CSS file.
o CSS makes it easy to change styles across several pages at once.
o CSS is used to define styles for your web pages, including the design,
layout and variations in display for different devices and screen sizes.
ADVANTAGES OF CSS
Lightweight code.
Greater accessibility.
Browser Compatibility:
o CSS stylesheets increase your websi adaptability and ensure that more
visitors will be able to view you website.
o -It can control the layout of multiple web pages all at once.
CSS SYNTAX
3
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
EXAMPLE
<html>
<head>
<style>
body
{
background-color: lightblue;
}
h1
{
color: white;
text-align: center;
}
p
{
font-family: verdana;
font-size: 20px;
}
</style>
</head>
<body>
</body>
</html>
4
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
OUTPUT
When a browser reads a style sheet, it will format the HTML document
according to the information in the style sheet.
1.INTERNAL CSS
o An internal style sheet may be used if one single HTML page has a
unique style.
o The internal style is defined inside the <style> element, inside the
head section.
o Internal styles are defined within the <style> element, inside the
<head> section of an HTML page:
o Place the CSS styles within a <style> tag inside the HTML file,
usually inside the <head> section.
5
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
<html>
<head>
<!-- Using Internal CSS -->
<style>
h3 {
color: red;
}
</style>
</head>
<body>
<!-- CSS is applied here -->
<h3>Welcome To Internal CSS </h3>
<p>CSS </p>
</body>
</html>
OUTPUT
2. INLINE CSS
To use inline styles, add the style attribute to the relevant element.
The style attribute can contain any CSS property.
6
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
EXAMPLE
Inline styles are defined within the "style" attribute of the relevant element:
Use the style attribute on the HTML element to add styles to the web page.
It is used for small projects.
<html>
<body>
<!-- Using Inline CSS -->
<h3 style="text-align: center;">
Welcome To CSS
</h3>
OUTPUT
3.EXTERNAL 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.
7
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
EXAMPLE
<html>
<head>
<link rel="stylesheet" href="mystyle.css">
</head>
<body>
<h1>This is a heading</h1>
<p>This is a paragraph.</p>
</body>
</html>
o An external style sheet can be written in any text editor, and must be
saved with a .css extension.
o The external .css file should not contain any HTML tags.
Body
{
background-color: lightblue;
}
h1
{
color: navy;
margin-left: 20px;
}
OUTPUT
8
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
CSS SELECTORS
The element selector selects HTML elements based on the element name.
EXAMPLE
<html>
<head>
<style>
p{
text-align: center;
color: red;
}
</style>
</head>
<body>
<p>Every paragraph will be affected by the style.</p>
<p id="para1">Me too!</p>
<p>And me!</p>
</body>
</html>
9
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
OUTPUT
CSS ID SELECTOR
<html>
<head>
<style>
#para1 {
text-align: center;
color: red;
}
</style>
</head>
<body>
</body>
</html>
10
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
OUTPUT
</body>
</html>
11
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
OUTPUT
The universal selector (*) selects all HTML elements on the page.
EXAMPLE
<html>
<head>
<style>
*{
text-align: center;
color: blue;
}
</style>
</head>
<body>
<h1>Hello world!</h1>
</body>
</html>
12
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
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):
h1
{
text-align: center;
color: red;
}
h2
{
text-align: center;
color: red;
}
p
{
text-align: center;color: red;
}
13
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
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
GROUPING STYLES
14
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
EXAMPLE:
h1, h2, h3
{
font-size: 10px;
color: green;
}
It improves the performance by reducing page loading time and save storage
space.
15
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
XML
Extensible Markup Language (XML) is a type of markup language that
establishes a set of guidelines for encoding texts in a way that is both machine-
and human-readable.
For storing and transferring data on the web and in many other applications,
XML is widely used. XML steps in as a versatile tool for encoding and
organizing data in a way that both humans and machines can comprehend.
SYNTAX
EXAMPLE
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
The XML above does not DO anything. XML is just information wrapped in
tags.
Someone must write a piece of software to send, receive, store, or display it:
16
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Note
To: Tove
From: Jani
Reminder
Don't forget me this weekend!
<book>
<title>Harry Potter and the Sorcerer's Stone</title>
<author>J.K.Rowling</author>
<year>1997</year>
</book>
The tags in the example above (like <to> and <from>) are not defined in any
XML standard. These tags are "invented" by the author of the XML document.
HTML works with predefined tags like <p>, <h1>, <table>, etc.
With XML, the author must define both the tags and the document structure.
17
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
APPLICATIONS OF XML
FEATURES OF XML
Flexibility: XML is a flexible data format as it allows you to create your own
custom tags to meet your specific needs.
Extensibility: XML is extensible as it enables you to add new features to
XML without breaking existing applications.
Platform-independence: XML files can be read and processed on any
platform, regardless of the operating system or programming language.
Human-readability: XML files are also human-readable, which makes them
easy to edit and maintain.
Machine-readability: XML files can be easily parsed and processed by
computers. This makes XML ideal choice to store and exchange.
ADVANTAGES OF XML
18
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
It uses the Dynamic Object Model to modify settings, properties, and methods.
HTML:
HTML stands for Hypertext Markup Language and it is a client-side
markup language. It is used to build the block of web pages.
Javascript:
It is a Client-side Scripting language. Javascript is supported by most of
browsers, and also has cookie collection to determine the user’s needs.
CSS:
The abbreviation of CSS is Cascading Style Sheet. It helps in the styling of
the web pages and helps in designing of the pages. The CSS rules for DHTML
will be modified at different levels using JS with event handlers which adds a
significant amount of dynamism with very little code.
DOM:
It is known as a Document Object Model which acts as the weakest link in
it. The only defect in it is that most of the browsers does not support DOM. It is a
way to manipulate the static content.
19
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Uses of DHTML
o It is used for designing the animated and interactive web pages that
are developed in real-time.
o DHTML helps users by animating the text and images in their
documents.
o It allows the authors for adding the effects on their pages.
o It also allows the page authors for including the drop-down menus or
rollover buttons.
o This term is also used to create various browser-based action games.
Features of DHTML
Its simplest and main feature is that we can create the web page
dynamically.
Dynamic Style is a feature, that allows the users to alter the font, size,
color, and content of a web page.
20
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
It provides the facility for using the events, methods, and properties.
And, also provides the feature of code reusability.
It also provides the feature in browsers for data binding.
Using DHTML, users can easily create dynamic fonts for their web
sites or web pages.
With the help of DHTML, users can easily change the tags and their
properties.
The web page functionality is enhanced because the DHTML uses
low-bandwidth effect.
21
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
A DTD defines the structure and the legal elements and attributes of an
XML document.
XML DTD
The purpose of a DTD is to define the structure and the legal elements and
attributes of an XML document:
Note.dtd:
<!DOCTYPE note
[
<!ELEMENT note (to,from,heading,body)>
<!ELEMENT to (#PCDATA)>
<!ELEMENT from (#PCDATA)>
<!ELEMENT heading (#PCDATA)>
<!ELEMENT body (#PCDATA)>
]>
!DOCTYPE note - Defines that the root element of the document is note
22
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
!ELEMENT note - Defines that the note element must contain the elements: "to,
from, heading, body"
!ELEMENT to - Defines the to element to be of type "#PCDATA"
!ELEMENT from - Defines the from element to be of type "#PCDATA"
!ELEMENT heading - Defines the heading element to be of type "#PCDATA"
!ELEMENT body - Defines the body element to be of type "#PCDATA"
Document Type Definition and XML Schema Definition both contain a set
of rules that control the structure and elements of XML files, but they are different
in syntax and usage. They check whether an XML document has a valid structure
or not.
DTD stands for Document Type Definition and DTD contains a set of rules
that control the structure and elements of XML files. It is used to describe the
attributes of XML language precisely. It can be classified into two types namely
internal DTD and external DTD. It can be specified inside a document or outside a
document. DTD mainly checks the grammar and validity of an XML document.
Features of DTD
It defines the compulsory and optional elements in the XML document.
It validates the structure of the XML document.
It checks for the grammar of the XML document.
It describes the order in which the element occurs.
Advantages of DTD
We can define our own format for the XML files by DTD.
It helps in validation of XML file.
It provides us with a proper documentation.
It enables us to describe a XML document efficiently.
Disadvantages of DTD
DTDs are hard to read and maintain if they are large in size.
It is not object oriented.
The documentation support is limited.
DTD doesn’t support namespaces.
23
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
The DOM can be used to build documents, navigate their structure, and add,
modify, or delete elements and content.
The Document Object Model (DOM) is a programming API for HTML and
XML documents. It defines the logical structure of documents and the way a
document is accessed and manipulated.
When a web page is loaded, the browser creates a Document Object Model
of the page.
The HTML DOM model is constructed as a tree of Objects:
The HTML DOM Tree of Objects
24
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
HTML DOM methods are actions you can perform (on HTML Elements).
HTML DOM properties are values (of HTML Elements) that you can set or
change.
The HTML DOM can be accessed with JavaScript (and with other
programming languages).
In the DOM, all HTML elements are defined as objects.
The programming interface is the properties and methods of each object.
A property is a value that you can get or set (like changing the content of an
HTML element).
A method is an action you can do (like add or deleting an HTML element).
<html>
<body>
<h2>My First Page</h2>
<p id="demo"></p>
<script>
document.getElementById("demo").innerHTML = "Hello World!";
</script>
</body>
</html>
25
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
OUTPUT
My First Page
Hello World!
The easiest way to get the content of an element is by using the innerHTML
property.
The innerHTML property can be used to get or change any HTML element,
including <html> and <body>.
The HTML DOM document object is the owner of all other objects in your web
page.
If you want to access any element in an HTML page, you always start with
accessing the document object.
Below are some examples of how you can use the document object to access and
manipulate HTML.
26
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Method Description
Dynamic content
The HTML DOM allows JavaScript to change the style of HTML elements.
27
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Example
<html>
<body>
<p id="p2">Hello World!</p>
<script>
document.getElementById("p2").style.color = "blue";
</script>
</body>
</html>
OUTPUT
Using Events
The HTML DOM allows you to execute code when an event occurs.
An element is clicked on
The page has loaded
Input fields are changed
This example changes the style of the HTML element with id="id1", when the user
clicks a button:
<html>
<body>
<h1 id="id1">My Heading 1</h1>
<button type="button"
onclick="document.getElementById('id1').style.color = 'red'">
28
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Click Me!</button>
</body>
</html>
OUTPUT
CSS POSITIONING
Position
Property Description
29
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Position
Property Description
1. Static Positioning
Static is the default position of an element. It does not accept properties
like top, left, right, or bottom.
<html>
<head>
<style>
div {
border: 1px solid black;
padding: 10px;
margin: 10px;
}
</style>
</head>
<body>
<div>Box 1</div>
<div>Box 2</div>
</body>
</html>
30
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
OUTPUT
2. Relative Positioning
Relative positioning places an element relative to its normal position.
You can move it using top, left, right, or bottom.
<html>
<head>
<style>
div {
border: 1px solid black;
padding: 10px;
margin: 10px;
}
.relative {
position: relative;
top: 20px;
left: 30px;
}
</style>
</head>
<body>
<div>Box 1</div>
<div class="relative">Box 2</div>
</body>
</html>
OUTPUT
31
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
3. Absolute Positioning
Absolute positioning removes the element from the document flow and
places it relative to the nearest ancestor with a positioning context (relative,
absolute, or fixed).
<html>
<head>
<style>
.container {
position: relative;
width: 300px;
height: 200px;
border: 2px solid black;
margin: 20px auto;
}
.absolute {
position: absolute;
top: 50px;
left: 50px;
background-color: pink;
padding: 10px;
}
</style>
</head>
<body>
<div class="container">
<p>Container with Relative Positioning</p>
<div class="absolute">Absolutely Positioned Element</div>
</div>
</body>
</html>
OUTPUT
32
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
The pink box (.absolute) is positioned 50px down and 50px right within the
.container.
It does not affect other elements in the flow.
4. Fixed Positioning
Fixed positioning removes the element from the flow and positions it
relative to the viewport. It remains in place even when the page scrolls.
<html>
<head>
<style>
.fixed {
position: fixed;
top: 10px;
right: 10px;
background-color: lightgreen;
padding: 20px;
border: 2px solid black;
}
.content {
height: 1200px;
padding: 10px;
}
</style>
</head>
<body>
33
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
OUTPUT
The fixed element stays at the top-right corner of the viewport even as the user
scrolls.
5. Sticky Positioning
Sticky positioning switches between relative and fixed based on the scroll
position
<html>
<head>
<style>
.sticky {
position: sticky;
top: 0;
background-color: yellow;
padding: 10px;
}
</style>
</head>
<body>
<div class="sticky">I am sticky</div>
<p>Scroll down to see the effect.</p>
<div style="height: 1000px;"></div>
</body>
34
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
</html>
OUTPUT
The sticky element stays at the top of the viewport as you scroll but only
within its containing element.
EVENT BUBBLING
<html>
<head>
<title>Event Bubbling Example</title>
</head>
<body>
<div id="parent" style="padding: 20px; background-color: lightblue;">
Parent Div
<button id="child">Click Me</button>
35
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
</div>
<script>
document.getElementById("parent").addEventListener("click", function()
{
alert("Parent Div Clicked!");
});
document.getElementById("child").addEventListener("click", function()
{
alert("Button Clicked!");
});
</script>
</body>
</html>
OUTPUT
If you click the button, the event fires on the button first (child).
Then, it bubbles up and triggers the event on the parent <div>.
36
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
document.getElementById("child").addEventListener("click", function(event) {
alert("Button Clicked!");
event.stopPropagation(); // Prevents bubbling to parent
});
Event bubbling helps in event delegation, reducing the need to add multiple event
listeners.
Use stopPropagation() if you don’t want events to propagate to parent elements.
DATA BINDING
Data binding is the process that couples two data sources together and
synchronizes them. With data binding, a change to an element in a data set
automatically updates in the bound data set.
Data binding may be used for many reasons, such as to link an application's
user interface (UI) and the data it displays, for data entry, reporting and in text box
elements. It also lets internet users manipulate the representation of data in the
elements of a web page without needing to use a complicated programming or
scripting processes.
Data and data objects of different logic functions can be bound together in
data binding. Data types with different languages can also be bound, such as data
binding Extensible Markup Language (XML) and UI.
Each data change in one data set automatically reflects in the other bound
data set. In binding syntax, the data source is the data provider, and the other data
set is the data consumer. The binding forms the link between the data provider and
the data consumer, enabling the connection between visual element data and a data
source.
Data binding eliminates the need for Document Object Model (DOM)
manipulation. DOM is an application programming interface, or API, for
Hypertext Markup Language (HTML) and XML.
37
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Types of data binding are typically defined by their data flow and include
the following:
One-way binding is a relatively simple type of data binding. Changes to the data
provider update automatically in the data consumer data set, but not the other way
around.
Two-way binding is where changes to either the data provider or the data consumer
automatically updates the other.
One-way-to-source binding is the reverse of one-way binding. Changes to the data
consumer automatically update the data provider but not the other way around.
One-time binding is where changes to the data provider do not automatically
update the data consumer. This approach is useful when only a snapshot of the data
is needed, and the data is static.
Data binding can be simple or complex. Microsoft defines simple data
binding as the ability to bind to a single data element. Complex data binding is
when multiple elements are bound together.
38
APOLLO ARTS AND SCIENCE COLLEGE CHENNAI
UNIT III WEB DESIGN AND DEVELOPMENT
Reporting. Binding is a common way to compile reports that display data from
a data source to a screen or printer.
Data entry. Data binding is also a common way to enter large amounts of data
and keep it updated and synchronized to a data source.
Lookup tables. Lookup tables are information tables that are typically a part of
larger data displays. Data binding and controls are used to display and change
data.
Master-detail formats. This is a model for communication protocols where
one device or process controls another. These formats may have two tables of
data bound together.
Data binding tools
Data binding tools include the following:
Visual Studio is a Microsoft product that provides design tools for working
with custom objects as a data source in applications. Visual Studio is also used
to bind UI controls. Changes made to objects are automatically made in a
database.
Data Binding Library is a support library for Android developers that binds
UI components to data sources.
39