HTML& CSS (Eng)
HTML& CSS (Eng)
What is HTML?
HTML stands for HyperText Markup Language. It is the standard language for creating web
pages and web applications. It defines the structure of a webpage using tags.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Page Title</title>
</head>
<body>
<h1>Welcome to My Website</h1>
<p>This is a paragraph.</p>
</body>
</html>
Example:
html
<h1>Main Heading</h1>
<h2>Subheading</h2>
<p>This is a paragraph explaining some content.</p>
Example:
html
An HTML element consists of a start tag, content, and an end tag. Example:
html
Most HTML elements have opening and closing tags. Example: <h1></h1>. Some, like <img>,
are self-closing.
Attributes in HTML
Attributes provide additional information about elements. They are always in the opening tag,
like class, id, and title.
Example:
html
Module 4: Lists
Ordered Lists
Example:
html
<ol>
<li>First item</li>
<li>Second item</li>
</ol>
Unordered Lists
Example:
html
<ul>
<li>Item one</li>
<li>Item two</li>
</ul>
Description Lists
Use <dl> for description lists, <dt> for terms, and <dd> for descriptions.
Example:
html
<dl>
<dt>HTML</dt>
<dd>HyperText Markup Language</dd>
<dt>CSS</dt>
<dd>Cascading Style Sheets</dd>
</dl>
Creating Hyperlinks
Example:
html
<a href="https://www.example.com">Visit Example</a>
Example:
html
Inserting Images
Use the <img> tag to insert images. Always include the alt attribute for accessibility.
Example:
html
Module 6: Tables
Tables use the following tags: <table>, <tr> (table row), <th> (table header), and <td>
(table data).
Example:
html
<table border="1">
<tr>
<th>Name</th>
<th>Age</th>
</tr>
<tr>
<td>John</td>
<td>25</td>
</tr>
</table>
Use the border, cellpadding, and cellspacing attributes to control table appearance.
Forms allow users to submit data to the server. Basic form elements include <form>, <input>,
<textarea>, and <button>.
Example:
html
Input Types
Form Attributes
Semantic HTML introduces meaning to elements. It is important for accessibility and SEO.
Common semantic tags include:
Example:
html
<header>
<h1>Website Title</h1>
</header>
Adding Audio
html
Embedding Videos
html
Form Validation
html
<select multiple>
<option>Option 1</option>
<option>Option 2</option>
</select>
HTML5 introduces new input types like date, time, color, and range, along with semantic
elements like <article>, <figure>, <progress>, and <meter>.
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Simple Webpage</title>
</head>
<body>
<header>
<h1>My Website</h1>
</header>
<nav>
<a href="#home">Home</a> |
<a href="#about">About</a> |
<a href="#contact">Contact</a>
</nav>
<section id="home">
<h2>Welcome to My Website</h2>
<p>This is a simple webpage layout.</p>
</section>
<footer>
<p>© 2024 My Website</p>
</footer>
</body>
</html>
DHTML is not a new language on its own but rather a combination of:
1. HTML (HyperText Markup Language): Provides the basic structure of the web page.
2. CSS (Cascading Style Sheets): Styles and visually formats HTML elements.
3. JavaScript: Adds interactivity and dynamic behavior to HTML elements.
4. DOM (Document Object Model): A programming interface for HTML documents. It
represents the page so JavaScript can interact with the structure, style, and content
dynamically.
Features of DHTML
Content Manipulation: With DHTML, you can modify the content of HTML elements without
refreshing the page. For example, you can change text, images, or entire sections dynamically.
Example: Changing the text of a paragraph on a button click.
html
<script>
function changeText() {
document.getElementById("content").innerHTML = "This is dynamic
text.";
}
</script>
1.
Dynamic Style Changes: You can dynamically change the styles of elements (e.g., color, size,
position) on the page without reloading it.
Example: Changing the background color of a <div> when the user clicks a button.
html
<script>
function changeColor() {
document.getElementById("box").style.backgroundColor = "blue";
}
</script>
2.
Dynamic Positioning of Elements: Using DHTML, you can change the position of elements on
the page dynamically, enabling animations or interactive user interfaces.
Example: Moving an image across the screen.
html
<script>
function moveRight() {
var img = document.getElementById("movingImage");
var currentLeft = parseInt(img.style.left);
img.style.left = currentLeft + 50 + "px";
}
</script>
3.
Event Handling: DHTML allows you to respond to various user events such as clicks, hovers,
or form submissions. This helps in making the page more interactive.
Example: Displaying a message when the user hovers over a text.
html
<script>
function showMessage() {
document.getElementById("message").style.display = "block";
}
function hideMessage() {
document.getElementById("message").style.display = "none";
}
</script>
4.
Form Validation: DHTML can be used to perform real-time form validation, ensuring users input
the correct data before submitting the form.
Example: Checking if an email input field is filled before allowing submission.
html
<script>
function validateForm() {
var email = document.getElementById("email").value;
if (email == "") {
document.getElementById("error").innerHTML = "Email is
required!";
return false;
}
return true;
}
</script>
5.
Advantages of DHTML
<script>
function toggleMenu() {
var menu = document.getElementById("menu");
if (menu.style.display === "none") {
menu.style.display = "block";
} else {
menu.style.display = "none";
}
}
</script>
1.
Image Slideshows: Websites often use DHTML to create dynamic image galleries or
slideshows that change images after a set period or based on user interaction.
Example: Simple image slideshow.
html
<script>
var images = ["image1.jpg", "image2.jpg", "image3.jpg"];
var currentIndex = 0;
function showNextImage() {
currentIndex = (currentIndex + 1) % images.length;
document.getElementById("slideshow").src = images[currentIndex];
}
setInterval(showNextImage, 2000);
</script>
2.
3. Form Validation Feedback: Provide real-time feedback while the user fills out a form,
such as checking if a username is already taken or if a password meets security
requirements.
1.
2.
3.
4.
style: Used to dynamically change the CSS properties of an element.
javascript
document.getElementById("elementID").style.color = "red";
5.
document.getElementById("buttonID").addEventListener("click",
function() {
alert("Button clicked!");
});
6.
Limitations of DHTML
1. Browser Compatibility Issues: Older browsers may not support all DHTML features,
leading to inconsistent behavior across different browsers.
2. Client-Side Dependency: Since DHTML relies on client-side technologies (HTML, CSS,
JavaScript), it can be affected by users disabling JavaScript or having incompatible
browsers.
3. Complexity: Large DHTML applications can become difficult to maintain and debug,
especially if not properly organized.
Conclusion
DHTML enables developers to create more dynamic, engaging, and interactive web pages by
combining HTML, CSS, JavaScript, and the DOM. It plays a crucial role in modern web
development by enhancing user experience and allowing for real-time updates and interactivity
without the need to reload web pages.
What is CSS?
CSS is a stylesheet language used to control the presentation of HTML documents. It helps
define the layout, colors, fonts, spacing, and overall appearance of a webpage.
Importance of CSS
● Presentation Control: CSS allows you to control the look and feel of a website.
● Separation of Content and Style: CSS separates content (HTML) from style (CSS),
making the code easier to maintain.
CSS Syntax
css
selector {
property: value;
}
Example:
css
h1 {
color: blue;
font-size: 24px;
}
CSS Selectors
Example:
css
/* Element Selector */
p {
color: green;
}
/* Class Selector */
.text-class {
font-weight: bold;
}
/* ID Selector */
#myParagraph {
font-style: italic;
}
The CSS box model treats elements as a box. Each element has content, padding, border, and
margin.
Example:
css
.box {
width: 300px;
height: 150px;
padding: 20px;
border: 5px solid black;
margin: 15px;
}
CSS Backgrounds and Colors
Background Properties
Example:
css
body {
background-color: lightblue; /* Solid color */
}
.header {
background-image: url('header.jpg'); /* Image */
background-repeat: no-repeat;
background-size: cover; /* Cover the entire area */
}
Text Color
Example:
css
h1 {
color: navy;
}
p {
color: darkgreen;
}
Font Properties
CSS allows you to set fonts, sizes, and styles.
Example:
css
body {
font-family: Arial, sans-serif; /* Font family */
font-size: 16px; /* Font size */
}
h2 {
font-weight: bold; /* Bold font */
font-style: italic; /* Italic font */
}
Example:
css
h1 {
text-align: center; /* Center alignment */
}
a {
text-decoration: none; /* Remove underline */
color: blue; /* Link color */
}
a:hover {
text-decoration: underline; /* Underline on hover */
}
CSS Layouts
Flexbox Layout
Flexbox is a powerful layout model that helps align elements within a flex container.
Example:
css
.container {
display: flex;
justify-content: space-between; /* Space between items */
align-items: center; /* Center items vertically */
}
.item {
flex: 1; /* Flex property */
margin: 10px; /* Margin between items */
}
Grid Layout
Example:
css
.grid-container {
display: grid;
grid-template-columns: repeat(3, 1fr); /* 3 columns */
gap: 10px; /* Gap between grid items */
}
.grid-item {
background-color: lightcoral;
padding: 20px; /* Padding within items */
}
CSS Positioning
Positioning Types
Example:
css
.relative {
position: relative;
top: 20px; /* Moves down */
}
.absolute {
position: absolute;
right: 0; /* Positioned to the right */
}
.fixed {
position: fixed;
bottom: 0; /* Sticks to the bottom */
}
Transitions
Example:
css
.button {
background-color: blue;
transition: background-color 0.3s ease; /* Transition effect */
}
.button:hover {
background-color: green; /* Change on hover */
}
Animations
Example:
css
@keyframes slide {
from {
transform: translateX(0);
}
to {
transform: translateX(100px);
}
}
.animated {
animation: slide 2s infinite; /* Animation name and duration */
}
Responsive Design
Media queries are used to create responsive designs, allowing you to apply different styles for
different devices.
Example:
css
h1 {
font-size: 24px; /* Smaller heading */
}
}
h1 {
font-size: 36px; /* Larger heading */
}
}
Pseudo-classes
Example:
css
a:hover {
color: red; /* Change color on hover */
}
input:focus {
border-color: blue; /* Change border color when focused */
}
Pseudo-elements
Pseudo-elements are used to style specific parts of elements.
Example:
css
p::first-line {
font-weight: bold; /* Style first line */
}
h1::before {
content: "Important: "; /* Add content before h1 */
color: red;
}
CSS Conclusion
CSS is essential for styling web pages. It allows you to create visually appealing and
user-friendly websites. Understanding CSS helps you design responsive and attractive
websites.