Adp Module 3
Adp Module 3
css
MODULE 03 22IT101-ADP
CSS – Introduction
CSS is acronym of Cascading Style Sheets. It helps to define the
presentation of HTML elements as a separate file known as CSS
file having .css extension.
What is CSS?
• CSS stands for Cascading Style Sheets, used to describe the
presentation and design of a web pages.
• Using CSS, you can control the color of the text, the style of
fonts, the spacing between paragraphs, how columns are
sized and laid out, what background images or colors are
used.
• CSS can control the layout of multiple web pages all at once.
css
MODULE 03 22IT101-ADP
css
MODULE 03 22IT101-ADP
• CSS Saves Time: You can write CSS once and then reuse same sheet in
multiple HTML pages.
• Pages Load Faster: If you are using CSS, you do not need to write HTML
tag or attributes every time. Just write one CSS rule of a tag and apply it to
all the occurrences of that tag.
• Easy Maintenance: To make a global change, simply change the style, and
all elements in all the web pages will be updated automatically.
• Superior Styles to HTML: CSS has a much wider array of attributes than
HTML, so you can get a far better look to your HTML page.
• Multiple Device Compatibility: For the same HTML document, different
versions of a website can be presented for different screen widths
• Global Web Standards: Now most of the HTML attributes are being
deprecated and it is being recommended to use CSS.
css
MODULE 03 22IT101-ADP
CSS Syntax
css
MODULE 03 22IT101-ADP
Types of CSS
There is no types in CSS, it actually refer - "In how many ways we can use CSS?"
So there are three ways to use CSS on HTML document.
Inline CSS: Inline CSS are directly applied on the HTML elements and it is the
most prioritize CSS among these three. This will override any external or
internal CSS.
Internal CSS: Internal CSS are defined in the HTML head section inside
of <style> tag to let the browser know where to look for the CSS.
External CSS: External CSS are defined in a separate file that contains only CSS
properties, this is the recommended way to use CSS when you are working on
projects. It is easy to maintain and multiple CSS files can be created and you
can use them by importing it into your HTML document using HTML <link> tag.
css
MODULE 03 22IT101-ADP
Working with Text and Fonts- Text Formatting, Text Effects, Fonts.
CSS Styling Text involves modifying appearance of text content by setting proper
color, alignment, letter-spacing and indention to make it more visually appealing.
css
MODULE 03 22IT101-ADP
Working with Text and Fonts- Text Formatting, Text Effects, Fonts.
CSS Styling Text involves modifying appearance of text content by setting proper
color, alignment, letter-spacing and indention to make it more visually appealing.
css
MODULE 03 22IT101-ADP
Working with Text and Fonts- Text Formatting, Text Effects, Fonts.
CSS Text Color Property
<!DOCTYPE html>
<html>
<body>
<p style = "color: blueviolet;"> Color Name: blueviolet; </p>
<p style = "color:#ff00ff;"> Hexadecimal value: #ff00ff; </p>
<p style = "color: rgb(255,124,100);"> RGB value: rgb(255, 124,
100); </p>
</body>
</html>
css
MODULE 03 22IT101-ADP
CSS Fonts allows to customize font style of webpages using various font related
properties. In this tutorial we will understand the font styling in CSS.
Syntax
selector { font-family: family-name, generic-family; }
css
MODULE 03 22IT101-ADP
<html> <head>
<style> p { font-family: Lucida Handwriting, Cursive; } </style>
<style> .font-size-example { font-size: 20px; }
.font-weight-example { font-weight: bold; }
.font-style-example { font-style: italic; } </style> </head>
<body>
<p > This is a font that written in Lucida Handwriting. THis is a font that
looks like human handwriting. </p>
<p class="font-size-example"> This is an example of text with an adjusted
font size. </p>
<p class="font-weight-example"> This is an example of text with an adjusted
font weight. </p>
<p class="font-style-example"> This is an example of text with an adjusted
font style. </p>
</body> </html>
css
MODULE 03 22IT101-ADP
Types of Selectors
• Universal Selectors
• Element Selectors
• Class Selectors
• Id Selectors
• Attribute Selectors
• Group Selectors
• Pseudo-element Selectors
• Pseudo-class Selectors
• Descendant Selectors
• Child Selectors
• Adjacent Sibling Selectors
• General Sibling Selectors
css
MODULE 03 22IT101-ADP
Syntax
* { margin: 0; padding: 0; }
As per the above syntax, the universal selector is used to apply a margin
and padding of 0 to all HTML elements.
Example
Following example demonstrates the use of a universal selector (*):
css
MODULE 03 22IT101-ADP
<html>
<head>
<style> *
{ margin: 0; padding: 0; background-color: peachpuff; color:
darkgreen; font-size: 25px; }
</style>
</head>
<body> <h1>Universal selector (*)</h1>
<div> Parent element
<p>Child paragraph 1</p>
<p>Child paragraph 2</p> </div>
<p>Paragraph 3</p>
</body>
</html>
css
MODULE 03 22IT101-ADP
Syntax
#style-p { color: green; font-size: 25px; }
#style-h1 { text-decoration-line: underline; color: red; }
css
MODULE 03 22IT101-ADP
Example
Following example demonstrates the use of an id selector, where #style-div,
#tutorial and #stylePoint are the id selectors applied on the elements:
<html>
<head>
<style> #style-div { border: 5px inset gold; width: 300px; text-align: center; }
#tutorial{ color: green; font-size: 20px; }
#stylePoint{ color: black; font-size: 15px; font-weight: bold; }
</style>
</head>
<body> <div id="style-div">
<div id="tutorial"> Tutorials <span id="stylePoint"> Point </span> </div>
<p> Here we used ids to style different elements. </p> </div>
</body>
</html>
css
MODULE 03 22IT101-ADP
Syntax
.sideDiv { text-decoration-line: underline; }
.topDiv { color: green; font-size: 25px; }
css
MODULE 03 22IT101-ADP
css
MODULE 03 22IT101-ADP
css
MODULE 03 22IT101-ADP
Syntax
css
MODULE 03 22IT101-ADP
Syntax
.multibackgrounds { background: background1, background2, /* …, */
backgroundN; }
css
MODULE 03 22IT101-ADP
css
MODULE 03 22IT101-ADP
css
MODULE 03 22IT101-ADP
css
MODULE 03 22IT101-ADP
.btn {
border: none; /* Remove borders */
color: white; /* Add a text color */
padding: 14px 28px; /* Add some padding */
cursor: pointer; /* Add a pointer cursor on mouse-over */
}
css
MODULE 03 22IT101-ADP
css
MODULE 03 22IT101-ADP
css
MODULE 03 22IT101-ADP
css
MODULE 03 22IT101-ADP
css
MODULE 03 22IT101-ADP
css
MODULE 03 22IT101-ADP
css
MODULE 03 22IT101-ADP
css
MODULE 03 22IT101-ADP
css
MODULE 03 22IT101-ADP
Example
Specify a horizontal and a vertical shadow:
div {
box-shadow: 10px 10px;
}
css
MODULE 03 22IT101-ADP
Thank you
css
JAVASCRIPT
JAVASCRIPT
• JavaScript is the world's most popular programming language.
• JavaScript is the programming language of the Web.
• JavaScript is easy to learn.
JAVASCRIPT
• JavaScript is one of the 3 languages all web developers must learn:
• 1. HTML to define the content of web pages
• 2. CSS to specify the layout of web pages
• 3. JavaScript to program the behavior of web pages
• JavaScript Can Change HTML Attribute Values
DISPLAY DATA IN JAVASCRIPT
JavaScript can "display" data in different ways:
• Writing into an HTML element, using innerHTML.
• Writing into the HTML output using document.write().
• Writing into an alert box, using window.alert().
• Writing into the browser console, using console.log().
Simple program in JavaScript
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script>
document.write('Hello World');
</script>
</body>
</html>
Simple program in JavaScript
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script>
alert('Hello World');
</script>
</body>
</html>
VARIABLES IN JAVASCRIPT
In JavaScript, variables are used to store data values that can be
referenced and manipulated. There are three ways to declare variables
in JavaScript:
• var - The traditional way of declaring variables. It has function scope
or global scope.
• let - A more modern way to declare variables. It has block scope.
• const - Used to declare variables that cannot be reassigned (constant
values). It also has block scope.
EXAMPLE
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JavaScript Variables Example</title>
</head>
<body>
<h1>Understanding JavaScript Variables</h1>
<script>
EXAMPLE
// Using 'var' to declare a variable
var name = "John"; // var is function-scoped
console.log(name); // Output: John
// Using 'let' to declare a variable
let age = 30; // let is block-scoped
console.log(age); // Output: 30
// Using 'const' to declare a variable
const country = "USA"; // const cannot be reassigned
console.log(country); // Output: USA
EXAMPLE
// Changing the value of 'let' variable
age = 35;
console.log(age); // Output: 35
// Uncommenting the next line will result in an error because you cannot reassign a 'const' variable
// country = "Canada"; // Error: Assignment to constant variable.
// 'var' allows redeclaration within the same scope
var name = "Alice"; // No error, redeclaring 'name'
console.log(name); // Output: Alice
// 'let' and 'const' do not allow redeclaration in the same scope
// let age = 25; // Error: Identifier 'age' has already been declared
// const country = "Canada"; // Error: Identifier 'country' has already been declared
</script>
</body>
</html>
Key Concepts
1. var:
• Declares a variable that is function-scoped or globally scoped if declared outside a
function.
• Can be re declared and reassigned.
• Less preferred in modern JavaScript due to its function-level scoping behavior.
2. let:
• Declares a variable with block scope, which means the variable is accessible only within
the block it is declared in (e.g., within a loop, condition, or function).
• Can be reassigned but not re declared in the same scope.
3. const:
• Declares a constant variable that cannot be reassigned after its initial assignment.
• Has block scope, just like let.
• You cannot re declare a const variable, and you cannot change its value after it’s set.
Key Concepts
• Use let when you need to reassign the variable later.
• Use const for variables that won't be reassigned, ensuring immutability.
• Avoid using var in modern JavaScript, unless necessary for backward
compatibility.
Sample Programs
// Get the current date
var today = new Date();
// Get the day of the month
var dd = today.getDate();
// Get the month (adding 1 because months are zero-based)
var mm = today.getMonth() + 1;
// Get the year
var yyyy = today.getFullYear();
OPERATORS
1. Arithmetic Operators
These operators are used to perform basic mathematical operations.
•Addition (+): Adds two values.
•Subtraction (-): Subtracts the second value from the first.
•Multiplication (*): Multiplies two values.
•Division (/): Divides the first value by the second.
•Modulus (%): Returns the remainder of a division.
•Exponentiation (**): Performs exponentiation (raises a number to a power).
•Increment (++): Increases a variable's value by 1.
•Decrement (--): Decreases a variable's value by 1
OPERATORS -EXAMPLE
let x = 10;
let y = 5;
console.log(x + y); // 15 (Addition)
console.log(x - y); // 5 (Subtraction)
console.log(x * y); // 50 (Multiplication)
console.log(x / y); // 2 (Division)
console.log(x % y); // 0 (Modulus)
console.log(x ** y); // 100000 (Exponentiation)
let z = 0;
console.log(z++); // 0 (Increment, post-increment)
console.log(z); // 1
Assignment Operators
These operators assign values to variables.
• Assignment (=): Assigns a value to a variable.
• Add and assign (+=): Adds the right operand to the left operand and
assigns the result.
• Subtract and assign (-=): Subtracts the right operand from the left
operand and assigns the result.
• Multiply and assign (*=): Multiplies the right operand by the left
operand and assigns the result.
• Divide and assign (/=): Divides the left operand by the right operand
and assigns the result.
Assignment Operators -EXAMPLE
let a = 5;
a += 3; // a = a + 3, so a becomes 8
console.log(a); // 8
a *= 2; // a = a * 2, so a becomes 16
console.log(a); // 16
a /= 4; // a = a / 4, so a becomes 4
console.log(a); // 4
Comparison Operators
• Equal to (==): Checks if two values are equal (without considering data type).
• Strict equal to (===): Checks if two values are equal and of the same type.
• Not equal to (!=): Checks if two values are not equal (without considering data
type).
• Strict not equal to (!==): Checks if two values are not equal and not of the same
type.
• Greater than (>): Checks if the left value is greater than the right.
• Less than (<): Checks if the left value is less than the right.
• Greater than or equal to (>=): Checks if the left value is greater than or equal to
the right.
• Less than or equal to (<=): Checks if the left value is less than or equal to the
right.
Comparison Operators -EXAMPLE
let m = 10;
let n = 5;
console.log(m == n); // false (Equal to)
console.log(m === '10'); // false (Strict equal to)
console.log(m != n); // true (Not equal to)
console.log(m !== '10'); // true (Strict not equal to)
console.log(m > n); // true (Greater than)
console.log(m < n); // false (Less than)
console.log(m >= 10); // true (Greater than or equal to)
console.log(m <= 5); // false (Less than or equal to)
Logical Operators
• Logical AND (&&): Returns true if both operands are true.
• Logical OR (||): Returns true if at least one operand is true.
• Logical NOT (!): Reverses the logical state of its operand.
EXAMPLE
let x = true;
let y = false;
console.log(x && y); // false (Logical AND)
console.log(x || y); // true (Logical OR)
console.log(!x); // false (Logical NOT)
Ternary (Conditional) Operator
• The ternary operator is a shorthand for if...else statements.
• It takes three operands.Condition ? expression_if_true :
expression_if_false
Syntax:
var var_name = [...iterable];
Spread Operator
• Example 1: In the example below two arrays are defined and they’re
merged into one using the spread operator (…). The merged array
contains elements in the order they’re merged.
<script>
var array1 = [10, 20, 30, 40, 50];
var array2 = [60, 70, 80, 90, 100];
var array3 = [...array1, ...array2];
console.log(array3);
</script>
Spread Operator
• Example 2: In this example, appending an element to a given iterable.
An array is defined and a value needs to be appended to it, so we use
the spread operator to spread all the values of the iterable and then
add the elements before or after according to the order we want.
<script>
var array1 = [10, 20, 30, 40, 50];
var array2 = [...array1, 60];
console.log(array2);
</script>
Spread Operator
Example 3: In this example, we will copy objects using the spread operator. obj2 is
given all the properties of obj1 using the spread operator(…). curly brackets must be
used to specify that object is being copied or else an error gets raised.
<script>
const obj = {
firstname: "Divit",
lastname: "Patidar",
};
const obj2 = { ...obj };
console.log(obj2);
</script>
Rest parameter
• Rest parameter: The rest parameter is converse to the spread
operator. while the spread operator expands elements of an iterable,
the rest parameter compresses them. It collects several elements. In
functions when we require to pass arguments but were not sure how
many we have to pass, the rest parameter makes it easier.
• Note: There must be only one rest parameter in javascript functions.
Syntax:
function function_name(...arguments) {
statements;
}
Rest parameter
• Example: In this example, the rest parameter condenses multiple
elements into a single element even when different numbers of
parameters are passed into the function, the function works as we
used the rest parameter. it takes multiple elements as arguments and
compresses them into a single element or iterable. further operations
are performed on the iterable.
Rest parameter
<script>
function average(...args) {
console.log(args);
var avg = args.reduce(function (a, b) {
return a + b;
}, 0) / args.length;
return avg;
}
console.log("average of numbers is : "
+ average(1, 2, 3, 4, 5));
console.log("average of numbers is : "
+ average(1, 2, 3));
</script>
Exercise
1. Write a JavaScript program to display the current day and time in
the following format.
Sample Output : Today is : Tuesday.
Current time is : 10 PM : 30 : 38
1. Write a JavaScript program to calculate multiplication and division
of two numbers (input from the user).
Sample form :
DESIGN AND DEVELOP A SIMPLE CALANDER
USING HTML,CSS AND JAVASCRIPT