[go: up one dir, main page]

0% found this document useful (0 votes)
45 views9 pages

Program 3 & 4

Uploaded by

KMC PRANAV
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views9 pages

Program 3 & 4

Uploaded by

KMC PRANAV
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Program 3: Develop an external style sheet named as “style.

css” and provide


different styles for h2, h3, hr, p, div, span, time, img & a tags. Apply different
CSS selectors for tags and demonstrate the significance of each.
HTML file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Styles Example</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div>
<h2>This is a Heading Level 2</h2>
<h3>This is a Heading Level 3</h3>
<p>This is a paragraph. <span>This part is emphasized with a span.</span></p>
<p>Current time: <time> 12:00 PM </time></p>
<hr>
<p>Here’s an image:</p>
<img src="pexels-photo.webp" alt="Placeholder Image">
<p>For more information, visit <a href="https://www.example.com">this
link</a>.</p>
</div>
</body>
</html>
style.css
/* Styling h2 elements */
h2 {
color: navy;
font-size: 24px;
text-align: center;
}

/* Styling h3 elements */
h3 {
color: darkgreen;
font-size: 20px;
border-bottom: 2px solid lightgray;
}
/* Styling horizontal rules */
hr {
border: 1px solid lightblue;
margin: 20px 0;
}
/* Styling paragraph elements */
p{
font-size: 16px;
line-height: 1.5;
color: dimgray;
}
/* Styling div elements */
div {
background-color: #f9f9f9;
padding: 20px;
border-radius: 8px; }
/* Styling span elements */
span {
color: red;
font-weight: bold;
}

/* Styling time elements */


time {
font-style: italic;
color: green;
}

/* Styling img elements */


img {
max-width: 100%;
height: auto;
border: 2px solid gray;
}

/* Styling anchor (a) elements */


a{
color: royalblue;
text-decoration: none;
}

a:hover {
text-decoration: underline;
color: darkblue;
}
Explanation of CSS Selectors
1. Type Selector (e.g., `h2`, `h3`, `p`): Styles all elements of that type.
2. Class Selector (e.g., `.classname`): Styles all elements with the specified class
(not shown in this example).
3. ID Selector (e.g., `#idname`): Styles the element with the specified ID (not shown
in this example).
4. Universal Selector (`*`): Styles all elements (not shown in this example).
5. Descendant Selector (e.g., `div p`): Styles `p` elements that are inside `div`
elements (not shown in this example).
Usage
To see the styles in action:
1. Create the `style.css` file with the CSS code.
2. Create an HTML file with the HTML code.
3. Open the HTML file in a web browser to view the styled page.

To apply these styles, make sure to link the style.css file in the HTML file’s <head>
section:
html
<link rel="stylesheet" href="style.css">
This setup ensures that the various CSS selectors are demonstrated effectively,
showcasing their impact on different HTML elements.
PROGRAM 4: Develop HTML page named as “registration.html” having variety
of HTML input elements with background colors, table for alignment & provide
font colors & size using CSS styles.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Registration Form</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
}
table {
width: 50%;
margin: 50px auto;
border-collapse: collapse;
background-color: white;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
th, td {
padding: 20px;
text-align: left;
}
th {
background-color: #4CAF50;
color: white;
font-size: 18px;
}
td {
background-color: #f9f9f9;
}

input[type="text"], input[type="email"],
input[type="password"],
select, textarea {
width: 100%;
padding: 5px;
margin: 5px 0 15px;
border: 1px solid #ccc;
border-radius: 5px;
}

input[type="submit"]
{
background-color: green;
color: white;
padding: 15px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
input[type="submit"]:hover
{
background-color: green;
}
label {
font-size: 16px;
color: #333;
}
.form-group
{
margin-bottom: 20px;
}
</style>
</head>
<body>
<table>
<tr>
<th colspan="2">Registration Form</th>
</tr>
<tr>
<td colspan="2">
<form action="#" method="post">
<div class="form-group">
<label for="first-name">First Name:</label>
<input type="text" id="first-name" name="first-name" required>
</div>

<div class="form-group">
<label for="last-name">Last Name:</label>
<input type="text" id="last-name" name="last-name" required>
</div>

<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>

<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>

<div class="form-group">
<label for="gender">Gender:</label>
<select id="gender" name="gender" required>
<option value="">Select Gender</option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="other">Other</option>
</select>
</div>
<div class="form-group">
<label for="address">address:</label>
<textarea id="address" name="address" rows="4" required></textarea>
</div>
<input type="submit" value="Register">
</form>
</td>
</tr>
</table>
</body>
</html>
Explanation:
1. HTML Structure:
- A table is used to center and align the form elements.
- The form includes text input fields, email input, password input, a dropdown
(select), and a textarea.

2. CSS Styles:
- Basic styling for body and table to ensure a clean, centered layout.
- Styling for form elements to make them more user-friendly and visually appealing.
- Hover effect for the submit button to enhance user interaction.

You might also like