UNit 1^J2^J3 Notes wb
UNit 1^J2^J3 Notes wb
UNit 1^J2^J3 Notes wb
Q) HTML
4. Lists
• Ordered list (numbered): <ol>, with <li> for each item.
html
CopyEdit
<ol>
<li>First item</li>
<li>Second item</li>
</ol>
• Unordered list (bulleted): <ul>, with <li> for each item.
html
CopyEdit
<ul>
<li>First item</li>
<li>Second item</li>
</ul>
5. Tables
Used to create tables:
html
CopyEdit
<table>
<tr>
<th>Heading 1</th>
<th>Heading 2</th>
</tr>
<tr>
<td>Data 1</td>
<td>Data 2</td>
</tr>
</table>
6. Forms
Used to collect user inputs:
html
CopyEdit
<form action="/submit" method="post">
<label for="name">Name:</label>
<input type="text" id="name" name="name">
<input type="submit" value="Submit">
</form>
7. Semantic Tags
These improve the meaning of content:
• <header>: Defines a header.
• <footer>: Defines a footer.
• <section>: Defines sections of content.
• <article>: Represents an article.
• <nav>: Navigation links.
• <aside>: Sidebar or related content.
• <main>: Main content of the page.
class MyHandler(xml.sax.ContentHandler):
def startElement(self, name, attrs):
print(f"Start Element: {name}")
def characters(self, content):
print(f"Content: {content.strip()}")
def endElement(self, name):
print(f"End Element: {name}")
parser = xml.sax.make_parser()
parser.setContentHandler(MyHandler())
xml_data =
"""<person><name>Ayush</name><age>21</age><email>a
[email protected]</email></person>"""
import io
parser.parse(io.StringIO(xml_data))
Output:
mathematica
CopyEdit
Start Element: person
Start Element: name
Content: Ayush
End Element: name
Start Element: age
Content: 21
End Element: age
Start Element: email
Content: [email protected]
End Element: email
End Element: person
Hindi (WhatsApp style):
SAX ek event-driven, read-only model hai jo XML document
ko line-by-line (ya element-by-element) padhke process
karta hai. Yeh DOM se zyada fast aur memory-efficient hai,
lekin XML ko modify nahi kar sakta. SAX large XML files ke
liye accha hai.
SAX kaise kaam karta hai:
• Event-driven: Jab SAX XML ko padhta hai, to events
trigger hoti hain jaise startElement, endElement,
characters, etc., jinko aap handle kar sakte hain apne
code se.
• No tree structure: DOM ke unlike, SAX XML ko
sequentially process karta hai, bina tree banaye.
SAX Example (Python):
python
CopyEdit
import xml.sax
class MyHandler(xml.sax.ContentHandler):
def startElement(self, name, attrs):
print(f"Start Element: {name}")
def characters(self, content):
print(f"Content: {content.strip()}")
def endElement(self, name):
print(f"End Element: {name}")
parser = xml.sax.make_parser()
parser.setContentHandler(MyHandler())
xml_data =
"""<person><name>Ayush</name><age>21</age><email>a
[email protected]</email></person>"""
import io
parser.parse(io.StringIO(xml_data))
Output:
mathematica
CopyEdit
Start Element: person
Start Element: name
Content: Ayush
End Element: name
Start Element: age
Content: 21
End Element: age
Start Element: email
Content: [email protected]
End Element: email
End Element: person
UNIT -2 (CSS)
Q) What is CSS? (Cascading Style Sheets)
CSS is a language used to style and format the layout of web
pages. It controls the design, such as colors, fonts, spacing,
and positioning of elements on a webpage. Without CSS,
websites would look plain and unstyled.
Types of CSS
There are three types of CSS:
1. Inline CSS
o Written directly in an HTML element using the style
attribute.
o Example:
html
CopyEdit
<h1 style="color: blue;">Hello World</h1>
2. Internal CSS
o Defined in the <style> tag inside the <head>
section of an HTML document.
o Example:
html
CopyEdit
<html>
<head>
<style>
h1 {
color: red;
}
</style>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
3. External CSS
o Written in a separate .css file, linked to the HTML
file.
o Example:
html
CopyEdit
<link rel="stylesheet" href="styles.css">
Properties in CSS
CSS properties define how the elements should be styled.
Here are some common properties:
1. Color
o Defines the color of text or background.
o Example:
css
CopyEdit
p{
color: green;
}
2. Font-family
o Specifies the font of text.
o Example:
css
CopyEdit
h1 {
font-family: Arial, sans-serif;
}
3. Margin
o Defines the space outside the element.
o Example:
css
CopyEdit
div {
margin: 20px;
}
4. Padding
o Defines the space inside the element, between the
content and border.
o Example:
css
CopyEdit
div {
padding: 10px;
}
5. Background-color
o Sets the background color of an element.
o Example:
css
CopyEdit
body {
background-color: lightblue;
}
6. Border
o Adds a border around an element.
o Example:
css
CopyEdit
p{
border: 2px solid black;
}
Q) CSS Styling
1. Background Styling
In CSS, you can style the background of an element using
several properties, including color, images, gradients, and
more. Let’s look at the most commonly used background
properties:
• background-color
Sets the background color of an element.
css
CopyEdit
div {
background-color: lightblue;
}
• background-image
Sets an image as the background of an element. You
can use URLs for external images or local file paths.
css
CopyEdit
div {
background-image: url('background.jpg');
}
• background-size
Controls the size of the background image.
css
CopyEdit
div {
background-image: url('background.jpg');
background-size: cover; /* Makes sure the image covers the
whole area */
}
• background-repeat
Determines whether the background image should
repeat.
css
CopyEdit
div {
background-image: url('background.jpg');
background-repeat: no-repeat; /* Prevents image repetition
*/
}
• background-position
Positions the background image.
css
CopyEdit
div {
background-image: url('background.jpg');
background-position: center; /* Positions image at the
center */
}
• background
A shorthand property to combine all background-
related properties.
css
CopyEdit
div {
background: lightblue url('background.jpg') no-repeat
center/cover;
}
2. Text Formatting
CSS allows you to format the text in many ways, including
controlling font style, size, alignment, color, and more.
• font-family
Specifies the font type for text. You can list multiple
fonts as fallbacks.
css
CopyEdit
p{
font-family: 'Arial', sans-serif;
}
• font-size
Controls the size of the text.
css
CopyEdit
p{
font-size: 18px;
}
• font-weight
Controls the thickness of the text (bold, normal, etc.).
css
CopyEdit
p{
font-weight: bold;
}
• font-style
Specifies the style of the text (italic, normal, etc.).
css
CopyEdit
p{
font-style: italic;
}
• text-align
Aligns the text inside an element (left, right, center).
css
CopyEdit
p{
text-align: center;
}
• line-height
Sets the distance between lines of text.
css
CopyEdit
p{
line-height: 1.5;
}
• text-transform
Controls the capitalization of text (uppercase,
lowercase, capitalize).
css
CopyEdit
p{
text-transform: uppercase;
}
• color
Sets the color of the text.
css
CopyEdit
p{
color: red;
}
• letter-spacing
Sets the spacing between letters.
css
CopyEdit
p{
letter-spacing: 2px;
}
• text-decoration
Adds decorations like underline, line-through, or none.
css
CopyEdit
a{
text-decoration: underline;
}
</body>
</html>
/* ID */
#header {
font-size: 24px;
color: black;
}
html
CopyEdit
<!-- Applying class and ID -->
<button class="button">Click Me</button>
<div id="header">Welcome to the Page</div>
Key Differences:
• Classes can be used multiple times on a page, while
IDs should be used only once.
• Classes are selected using a dot (.) while IDs use a hash
(#).
Diagram:
First Diagram :
Second Diagram :
div {
display: block;
width: 100%;
background-color: lightblue;
}
o Behavior: The div will take up the full width of the
container and push the next element below it.
2. inline
o What it does: Makes the element an inline
element. Inline elements only take up as much
width as their content and do not start on a new
line.
o Examples of inline elements: <span>, <a>,
<strong>, etc.
Example:
css
CopyEdit
span {
display: inline;
color: red;
}
o Behavior: The span element will stay in the same
line as the surrounding text.
3. inline-block
o What it does: Makes the element behave like an
inline element, but allows you to set width and
height (unlike inline elements).
Example:
css
CopyEdit
.box {
display: inline-block;
width: 150px;
height: 100px;
background-color: lightgreen;
}
o Behavior: The element behaves like an inline
element but can still be sized (width and height).
4. none
o What it does: Hides the element entirely. The
element will not take up any space in the layout.
Example:
css
CopyEdit
.hidden {
display: none;
}
o Behavior: The element will not appear on the page,
and it will not affect the layout.
5. flex
o What it does: Makes the element a flex container.
This is used for creating flexible layouts where the
children of this element are flex items, and you can
control their alignment and distribution.
Example:
css
CopyEdit
.container {
display: flex;
justify-content: space-between;
}
o Behavior: The child elements inside .container will
be arranged in a row (by default) with space
between them.
Examples in Action:
Relative Positioning Example:
html
CopyEdit
<div class="relative">This is a relative element</div>
CSS:
css
CopyEdit
.relative {
position: relative;
top: 50px;
left: 50px;
background-color: lightblue;
}
• The .relative element will move 50px down and 50px to
the right, but it will still occupy the space it originally
would have in the document flow.
Fixed Positioning Example:
html
CopyEdit
<div class="fixed">I stay fixed at the bottom-right
corner!</div>
CSS:
css
CopyEdit
.fixed {
position: fixed;
bottom: 10px;
right: 10px;
background-color: lightgreen;
}
• The .fixed element will stay in the same position at the
bottom-right corner of the viewport, even when the
page is scrolled.
2. Align
The text-align property in CSS aligns the text horizontally
within its container.
Values of Text Alignment:
1. left: Aligns text to the left.
2. right: Aligns text to the right.
3. center: Centers the text.
4. justify: Stretches the text so that each line has equal
width.
Example:
html
CopyEdit
<p class="center">This is centered text.</p>
css
CopyEdit
.center {
text-align: center;
}
Vertical Alignment:
You can use the vertical-align property for inline elements or
table cells.
css
CopyEdit
.vertical {
vertical-align: middle;
}
3. Pseudo-class
A pseudo-class is a keyword added to selectors that
specifies a special state of the element.
Common Pseudo-classes:
1. :hover: Applies styles when the user hovers over an
element.
2. :focus: Applies styles when an element is focused.
3. :first-child: Targets the first child of an element.
4. :last-child: Targets the last child of an element.
5. :nth-child(n): Targets the nth child of an element.
Example:
html
CopyEdit
<a href="#" class="hover">Hover over me</a>
css
CopyEdit
.hover:hover {
color: red;
text-decoration: underline;
}
4. Navigation Bar
A navigation bar (navbar) is a section of a website that
contains links for navigation.
Example of a Simple Navbar:
html
CopyEdit
<nav>
<ul class="navbar">
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
</ul>
</nav>
css
CopyEdit
.navbar {
list-style-type: none;
background-color: #333;
padding: 10px;
overflow: hidden;
}
.navbar li {
float: left;
}
.navbar a {
display: block;
color: white;
text-decoration: none;
padding: 10px 20px;
}
.navbar a:hover {
background-color: #575757;
}
5. Image Sprites
Image sprites combine multiple images into one image file,
reducing the number of HTTP requests for faster loading.
How to Use Image Sprites:
1. Use background-position to display different parts of
the sprite image.
2. Set the width and height of the element to match the
desired sprite.
Example:
html
CopyEdit
<div class="icon icon-home"></div>
<div class="icon icon-contact"></div>
css
CopyEdit
.icon {
background-image: url('sprites.png');
background-repeat: no-repeat;
display: inline-block;
}
.icon-home {
background-position: 0 0;
width: 50px;
height: 50px;
}
.icon-contact {
background-position: -50px 0;
width: 50px;
height: 50px;
}
6. Attribute Selector
Attribute selectors allow you to style elements based on
their attributes and attribute values.
Syntax:
1. [attribute]: Selects elements with the specified
attribute.
2. [attribute="value"]: Selects elements with the specified
attribute and value.
3. [attribute^="value"]: Selects elements with attributes
that start with the specified value.
4. [attribute$="value"]: Selects elements with attributes
that end with the specified value.
5. [attribute*="value"]: Selects elements with attributes
that contain the specified value.
Example:
html
CopyEdit
<input type="text" class="field">
<input type="password" class="field">
css
CopyEdit
input[type="text"] {
border: 2px solid blue;
}
input[type="password"] {
border: 2px solid red;
}
2. Align
Text alignment ka kaam hai text ko horizontally ya vertically
align karna.
Example:
css
CopyEdit
.center {
text-align: center; /* Center alignment */
}
3. Pseudo-class
Pseudo-class ek special state ko represent karta hai, jaise
:hover, :focus.
Example:
css
CopyEdit
a:hover {
color: red;
}
4. Navigation Bar
Navigation bar ek website ka section hota hai jo links provide
karta hai.
Example:
css
CopyEdit
.navbar {
background-color: #333;
list-style: none;
overflow: hidden;
}
5. Image Sprites
Multiple images ko ek hi file mein combine karke sprites
banaya jaata hai.
Example:
css
CopyEdit
.icon-home {
background-position: 0 0;
}
6. Attribute Selector
Attributes ke basis par elements ko style karne ke liye use
hota hai.
Example:
css
CopyEdit
input[type="password"] {
border: 2px solid red;
}
1. JavaScript Document :
The document object in JavaScript is the entry point for
interacting with the web page. It represents the entire
webpage loaded in the browser. Using the document object,
you can access and manipulate any part of the webpage,
including elements, forms, styles, and content.
• Examples of Document Methods/Properties:
o document.title → Get or set the title of the
webpage.
o document.getElementById() → Access an element
by its ID.
o document.querySelector() → Select elements using
CSS selectors.
o document.body → Access the <body> part of the
webpage.
2. Forms in JavaScript :
A form in HTML is used to collect user inputs, such as text,
emails, passwords, etc. JavaScript can interact with forms
to:
• Validate user inputs (e.g., ensure the email is in a proper
format).
• Access or modify form fields (e.g., get or change the
value entered by a user).
• Handle form submissions (e.g., prevent the page from
refreshing and send the data to a server using
JavaScript).
WhatsApp-Style English
Bro, statements in JavaScript are like sentences you write to
tell the computer what to do. Each statement does
something specific — like declaring variables, running loops,
or making decisions.
Examples:
1. let age = 21; → Declare and assign a variable.
2. if (age > 18) { console.log("Adult"); } → Check if someone
is an adult or not.
3. for (let i = 0; i < 5; i++) { console.log(i); } → Print numbers
from 0 to 4 in a loop.
Simply put:
• Statements = Instructions for your program.
• End with ; most of the time.
Functions in JavaScript
Functions are reusable blocks of code that perform a
specific task. They help reduce repetition, make the code
modular, and improve readability.
Types of Functions
1. Function Declaration (Named Function)
A function that is defined with a specific name.
2. Function Expression
A function assigned to a variable.
3. Arrow Function (ES6)
A compact way of writing functions.
4. Anonymous Function
A function without a name, usually used inside other
code like event handlers.
5. Immediately Invoked Function Expression (IIFE)
A function that is executed as soon as it is defined.
2. Function Expression
Syntax:
javascript
CopyEdit
const variableName = function(parameters) {
// code to be executed
return result;
};
Example:
javascript
CopyEdit
const multiplyNumbers = function(a, b) {
return a * b;
};
4. Anonymous Function
Example:
javascript
CopyEdit
setTimeout(function() {
console.log("This runs after 2 seconds");
}, 2000);
Explanation (Hindi)
Anonymous function ka naam nahi hota. Iska use jyadatar
temporary tasks ke liye hota hai, jaise event handling ya
callbacks.
Q) AJAX Explanation
English:
AJAX stands for Asynchronous JavaScript and XML. It is a
technique used in web development that allows a web page
to update parts of its content without reloading the entire
page. This makes web applications faster, smoother, and
more user-friendly.
WhatsApp-style:
Bro, AJAX helps update parts of a webpage without
refreshing the whole page. Fast and smooth experience for
users!
Real-Life Example
English:
Imagine you’re chatting on WhatsApp Web. When a new
message arrives, the chat window updates with the message
without refreshing the entire page. This is done using AJAX.
Hindi (English Alphabets):
Socho, tum WhatsApp Web pe chat kar rahe ho. Jab naya
message aata hai, chat window update ho jata hai bina pura
page reload kiye. Ye sab AJAX ki wajah se hota hai.
Example Code
html
CopyEdit
<!DOCTYPE html>
<html>
<head>
<title>AJAX Example</title>
<script>
function loadData() {
// Create an XMLHttpRequest object
var xhr = new XMLHttpRequest();
Math Object:
1. Math.abs(x) – Absolute value of x.
2. Math.round(x) – Rounds x to the nearest integer.
3. Math.floor(x) – Rounds x down to the nearest integer.
4. Math.ceil(x) – Rounds x up to the nearest integer.
5. Math.max(...values) – Returns the largest number.
6. Math.min(...values) – Returns the smallest number.
7. Math.random() – Returns a random number between 0
and 1.
8. Math.pow(base, exponent) – Returns base raised to
the power of exponent.
9. Math.sqrt(x) – Returns the square root of x.
Date Object:
1. new Date() – Creates a new date object (current date
and time).
2. getFullYear() – Gets the year.
3. getMonth() – Gets the month (0-based index).
4. getDate() – Gets the day of the month.
5. getHours() – Gets the hours.
6. getMinutes() – Gets the minutes.
7. getSeconds() – Gets the seconds.
8. getMilliseconds() – Gets the milliseconds.
9. getDay() – Gets the day of the week (0 for Sunday, 1 for
Monday, etc.).
10. setFullYear(year) – Sets the year of the date.
11. toLocaleString() – Converts the date to a localized
string.
12. toISOString() – Converts the date to ISO format.
What is an IP Address?
An IP Address (Internet Protocol Address) is like your
home address on the internet. It helps other computers
know where to send data, similar to how letters are delivered
to a house. Every device connected to the internet, such as a
computer, phone, or server, has a unique IP address.
Types of IP Addresses:
There are two main types of IP addresses:
1. IPv4 (Internet Protocol version 4):
This is the most common type, written as four sets of
numbers separated by dots (e.g., 192.168.1.1). It allows
about 4 billion unique addresses, but with the growth
of the internet, these addresses are running out.
2. IPv6 (Internet Protocol version 6):
This is a newer type, written in hexadecimal (numbers
and letters), and it allows for a huge number of
addresses (about 340 undecillion). It looks something
like this: 2001:0db8:85a3:0000:0000:8a2e:0370:7334.
IP Address Classes:
IP addresses are divided into classes based on their range.
These classes help to organize and manage IP addresses.
• Class A:
Used for large networks (like big companies or ISPs).
The IP range is 1.0.0.0 to 127.255.255.255. The first part
is for the network, and the rest is for the hosts (devices).
• Class B:
Used for medium-sized networks. The range is
128.0.0.0 to 191.255.255.255. It gives more addresses
than Class A but is smaller than Class A.
• Class C:
Used for smaller networks. The range is 192.0.0.0 to
223.255.255.255. Often used by small businesses or
home networks.
• Class D:
Used for multicasting, where data is sent to multiple
recipients. The range is 224.0.0.0 to 239.255.255.255.
• Class E:
Reserved for experimental or future use. The range is
240.0.0.0 to 255.255.255.255.
Host and Network Part of an IP Address:
An IP address is divided into two main parts:
1. Network Part:
Identifies which network the device belongs to.
2. Host Part:
Identifies the specific device or host within that
network.
For example, in the IP address 192.168.1.1:
• The 192.168.1 part is the network address.
• The 1 part is the host address (the specific device on
that network).
Private vs Public IP Address:
• Private IP Addresses are used within a private network
(like your home Wi-Fi), and they aren't visible to the
outside world. Example: 192.168.x.x
• Public IP Addresses are used on the internet, and they
are globally unique. They allow the internet to find and
connect to your network. Example: 8.8.8.8 (Google’s
DNS server).
Example in Hindi (in English Alphabets):
IP address kya hai? IP address ek ghar ka address jaisa
hota hai, lekin yeh internet par hota hai. Jab aap internet
use karte ho, toh har device ka apna ek unique IP address
hota hai, jaise har ghar ka ek unique address hota hai.
IP Address ke Types:
1. IPv4:
Yeh sabse zyada use hota hai, aur 4 sets mein likha
hota hai, jaise 192.168.1.1. Isme 4 billion addresses ho
sakte hain.
2. IPv6:
Yeh naya version hai, jo numbers aur letters se likha
jaata hai, aur ismein bahut zyada addresses ho sakte
hain.
IP Classes:
• Class A: Badi networks ke liye.
• Class B: Medium-sized networks ke liye.
• Class C: Chhoti networks ke liye.
• Class D: Multicasting ke liye.
• Class E: Experimentation ke liye.
Host aur Network Part: Har IP address do parts mein
divided hota hai:
• Network Part: Yeh batata hai ki device kis network ka
hissa hai.
• Host Part: Yeh batata hai ki kis specific device ka IP hai.
Private aur Public IP:
• Private IP: Yeh aapke ghar ke network mein hota hai
(example: 192.168.x.x).
• Public IP: Yeh internet par visible hota hai (example:
8.8.8.8).
Q) What is a URL?
A URL stands for Uniform Resource Locator. It is the
address used to locate resources (like websites, images,
files, etc.) on the internet. Think of it as the "address" for a
specific location or resource available on the web.
Just like a home address helps you find a house, a URL helps
you find a particular webpage, image, or file online. When
you type a URL in the browser's address bar, the browser
knows where to go to fetch the content you requested.
Breakdown of a URL
A URL consists of several parts, which help the browser
understand exactly how to connect to the website or
resource. Let’s break down an example:
Example URL: https://www.example.com/page1
1. https://: This is called the protocol or scheme. It
defines how the data should be transferred over the
internet. In most cases, it’s either http or https. The s in
https stands for secure, meaning that the connection is
encrypted and safe from hackers.
2. www.example.com: This is the domain name. It
identifies the website you are trying to access. It’s like
the address of a house. Every website has its own
domain name that tells the browser which server to
connect to.
3. /page1: This is the path. It tells the browser which
specific page or resource on the website to open. If you
don’t include a path, the browser will usually open the
homepage of the website.
Thank you for your feedback! I understand that you want a
more detailed explanation. Let me explain the URL in both
languages with more clarity.
Breakdown of a URL
A URL consists of several parts, which help the browser
understand exactly how to connect to the website or
resource. Let’s break down an example:
Example URL: https://www.example.com/page1
1. https://: This is called the protocol or scheme. It
defines how the data should be transferred over the
internet. In most cases, it’s either http or https. The s in
https stands for secure, meaning that the connection is
encrypted and safe from hackers.
2. www.example.com: This is the domain name. It
identifies the website you are trying to access. It’s like
the address of a house. Every website has its own
domain name that tells the browser which server to
connect to.
3. /page1: This is the path. It tells the browser which
specific page or resource on the website to open. If you
don’t include a path, the browser will usually open the
homepage of the website.
Summary:
• URL = The address used to access resources on the
internet.
• It consists of protocol (like https://), domain name (like
www.example.com), and path (like /page1).
• Just like you need a street address to reach a house, you
need a URL to reach a webpage or file on the internet.