Web Technologies Overview
Web Technologies Overview
6. Web Security
Protecting websites and users from threats like:
- **Common vulnerabilities:**
- Cross-Site Scripting (XSS).
- SQL Injection.
- CSRF (Cross-Site Request Forgery).
- **Practices:**
- Use HTTPS for encrypted communication.
- Sanitize user inputs.
- Regularly update software.
### **HTML**
- HTML pages are divided into two main sections: head and body.
- The **head** contains metadata, such as the title, links to external resources, and meta
tags.
**Example:**
```html
<!DOCTYPE html>
<html lang=”en”>
<head>
<meta charset=”UTF-8”>
</head>
<body>
<h1>Welcome to My Page</h1>
</body>
</html>
```
- Formatting tags are used to style text elements for better readability and emphasis.
```html
```
**Example:**
```html
<table border=”1”>
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>John</td>
<td>25</td>
</tr>
</table>
```
**Example:**
```html
```
**Example:**
```html
```
#### **6. Meta Tags**
**Example:**
```html
```
- Frames divide a webpage into multiple sections, each displaying a different document.
**Example:**
```html
<frameset cols=”50%,50%”>
<frame src=”page1.html”>
<frame src=”page2.html”>
</frameset>
```
**Example:**
```html
<label for=”name”>Name:</label>
</form>
```
**Example:**
```html
<audio controls>
</audio>
</video>
```
**Example:**
```html
<script>
Navigator.geolocation.getCurrentPosition(position => {
Console.log(“Latitude:”, position.coords.latitude);
});
</script>
```
- **Form Validations:**
- Attributes like `required`, `pattern`, and `type` validate user input directly in the browser.
**Example:**
```html
```
- Tags like `<header>`, `<article>`, and `<section>` enhance the structure and improve SEO
rankings.
**Example:**
```html
<header>
<h1>Website Title</h1>
</header>
```
### **CSS**
- CSS separates content from presentation, making webpages easier to style and maintain.
**Example:**
```css
Selector {
Property: value;
Body {
Background-color: lightblue;
Color: black;
```
**Example:**
```css
Body {
Background-image: url(‘bg.jpg’);
Background-repeat: no-repeat;
Background-size: cover;
}
```
**Example:**
```css
H1 {
Color: red;
Background-color: yellow;
```
**Example:**
```css
P{
Text-align: center;
Text-transform: uppercase;
```
#### **6. Fonts**
**Example:**
```css
H1 {
Font-size: 24px;
```
**Example:**
```css
Div {
Border-radius: 10px;
```
#### **8. Margins and Padding**
- Margins create space outside elements, while padding creates space inside their
borders.
**Example:**
```css
Div {
Margin: 10px;
Padding: 20px;
```
**Example:**
```css
Ul {
List-style-type: square;
```
**Example:**
```css
A:hover {
Color: blue;
Body {
Background-color: lightgray;
```
- **Flexbox:**
**Example:**
```css
Div {
Display
- Introduced modules like Flexbox, Grid, and Media Queries for advanced layouts.
- Improved support for web fonts, making typography more dynamic and visually
appealing.
**Properties:**
```css
Div {
Border-radius: 10px;
```
**Properties:**
**Example:**
```css
@keyframes move {
0% { transform: translateX(0); }
Div {
```
**Properties:**
```css
Div {
Position: relative;
Display: inline-block;
Div::after {
Position: absolute;
Background-color: black;
Color: white;
Padding: 5px;
Border-radius: 5px;
Top: 100%;
Left: 50%;
Transform: translateX(-50%);
Display: none;
}
Div:hover::after {
Display: block;
```
- CSS styles enhance image appearance with borders, filters, and responsive behavior.
- Filters like `grayscale`, `sepia`, `blur`, and `drop-shadow` add creative effects.
- Responsive images can adapt to different screen sizes using relative units.
**Properties:**
**Example:**
```css
Img {
Filter: grayscale(50%);
Width: 100%;
Height: auto;
}
```
- They are defined in a `:root` selector and can be reused throughout the CSS.
**Properties:**
**Example:**
```css
:root {
--main-color: #3498db;
--font-size: 16px;
P{
Color: var(--main-color);
Font-size: var(--font-size);
```
#### **6. Flexbox**
- A CSS layout model for arranging items along a flexible row or column.
- Offers properties like `justify-content`, `align-items`, and `flex-wrap` for layout control.
**Properties:**
**Example:**
```css
.container {
Display: flex;
Justify-content: center;
Align-items: center;
```
- Enable responsive design by applying styles based on device characteristics like screen
size.
- Common breakpoints include 600px, 768px, and 1024px for small, medium, and large
devices.
**Example:**
```css
Body {
Background-color: lightgray;
```
**Properties:**
```css
A[href^=”https”] {
Color: green;
A[href$=”.pdf”] {
Text-decoration: underline;
```
**Properties:**
**Example:**
```css
Div {
Background: linear-gradient(to right, red, yellow);
```
**Properties:**
**Example:**
```css
A:hover {
Color: blue;
Input:focus {
Border-color: green;
```
#### **11. Pseudo-Elements**
- Style specific parts of an element, like the first line or content added before/after.
**Properties:**
**Example:**
```css
P::first-line {
Font-weight: bold;
H1::before {
Content: “★ “;
Color: gold;
```
**Properties:**
```html
<div class=”row”>
</div>
```
- Focuses on creating adaptable layouts for various devices and screen sizes.
**Properties:**
**Example:**
```css
Body {
Font-size: 12px;
```
- JavaScript syntax defines the set of rules for writing valid JavaScript code.
- Supports various data types (strings, numbers, booleans, arrays, objects), control
structures, and object-oriented programming.
**Example:**
```javascript
Console.log(message);
```
#### **2. Types of JavaScript**
- **Client-Side JavaScript**: Runs on the browser, enabling interactive features like form
validation, dynamic content updates, and DOM manipulation.
- **Server-Side JavaScript**: Runs on servers using platforms like Node.js for backend
processing, database interaction, and APIs.
- Variables store data values and can be declared using `var`, `let`, or `const`.
- `let` allows block-scoped variables, while `const` defines constants that cannot be
reassigned.
- Dynamic typing allows variables to hold different data types during execution.
**Example:**
```javascript
Const PI = 3.14159;
```
- Arrays store multiple values in a single variable and support ordered data.
**Example:**
```javascript
Console.log(fruits.length); // Outputs: 4
```
**Example:**
```javascript
Function add(a, b) {
Return a + b;
// Arrow function
```
#### **6. Conditions**
- JavaScript supports `if`, `else if`, `else`, and `switch` for conditional logic.
**Example:**
```javascript
Console.log(“Pass”);
} else {
Console.log(“Fail”);
```
- Loops repeat code blocks: `for`, `while`, `do-while`, and `forEach` for arrays.
- `break` exits the loop, while `continue` skips to the next iteration.
**Example:**
```javascript
For (let I = 1; I <= 5; i++) {
Console.log(i);
```
**Example:**
```javascript
```
- DOM (Document Object Model) manipulates HTML elements dynamically, allowing you to
traverse and modify the document tree.
**Example:**
```javascript
Let person = {
Name: “John”,
Age: 30,
Greet: function() {
Console.log(“Hello, “ + this.name);
};
Person.greet();
Element.innerHTML = “Welcome!”;
```
**Example:**
```javascript
```
#### **11. JavaScript Validations**
**Example:**
```javascript
Function validate() {
Alert(“Email is required!”);
Return false;
Return true;
```
**Example:**
```javascript
- Allows handling user actions like clicks, keypresses, mouse movements, etc.
**Example:**
```javascript
Document.getElementById(“btn”).addEventListener(“click”, function(event) {
Console.log(“Button clicked!”);
});
```
**Example:**
```javascript
Function greet(callback) {
Callback(“Hello!”);
Greet(function(message) {
Console.log(message);
});
```
**Example:**
```javascript
Function square(num) {
Return func(value);
```
**Example:**
```javascript
Let car = {
Brand: “Toyota”,
Start: function() {
Console.log(“Car started”);
};
Car.start();
```
**Example:**
```javascript
```
### ReactJS Overview with Properties, Information, and Examples
**Key Features:**
**Example:**
```jsx
Function App() {
```
#### **2. React Installation (Using create-react-app)**
```bash
Cd my-app
Npm start
```
- The above commands create a boilerplate React project and launch a development
server.
- **State and Props**: Manage dynamic data and communicate between components.
- **Hooks**: Functions like `useState` and `useEffect` for managing state and lifecycle in
functional components.
- **Context API**: Shares global data across components without prop drilling.
- **Pros:**
- **Cons:**
- Requires third-party libraries for full functionality (e.g., routing, state management).
- **ReactJS**:
- **AngularJS**:
- **React Native**: Used for building mobile applications with native performance using
React principles.
#### **7. React vs Vue**
- **React**:
- Focuses on UI development.
- **Vue**:
- Integrated framework with built-in solutions for routing and state management.
**Example:**
```jsx
```
```jsx
Function Greeting(props) {
```
**Lifecycle Methods:**
**Example:**
```jsx
Function Form() {
e.preventDefault();
alert(`Hello, ${name}!`);
};
Return (
<form onSubmit={handleSubmit}>
<button type=”submit”>Submit</button>
</form>
);
```
**Example:**
```jsx
Function ClickButton() {
Console.log(“Button clicked!”);
};
Return <button onClick={handleClick}>Click Me</button>;
```