Web Technology Lab Assignment 1
Web Technology Lab Assignment 1
Qns No.1
Program Statement: Create a HTML page that includes an image gallery
(3 images in one row) which acts as a link. Also, images should be with capƟon &
scales responsively to the page.
Ans:-
To create an HTML page that includes an image gallery with the specified requirements, we can use
HTML and CSS. The gallery will display three images in one row, each image will act as a link,
and each will have a caption. Additionally, the images will scale responsively to fit the screen size.
HTML (index.html):
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Responsive Image Gallery</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="gallery">
<!-- Image 1 -->
<a href="https://example.com/link1" class="gallery-item">
<img src="https://via.placeholder.com/300" alt="Image 1">
<div class="caption">Image 1</div>
</a>
<!-- Image 2 -->
<a href="https://example.com/link2" class="gallery-item">
<img src="https://via.placeholder.com/300" alt="Image 2">
<div class="caption">Image 2</div>
</a>
<!-- Image 3 -->
<a href="https://example.com/link3" class="gallery-item">
<img src="https://via.placeholder.com/300" alt="Image 3">
<div class="caption">Image 3</div>
</a>
</div>
</body>
</html>
CSS (styles.css):
css
Copy code
/* Basic reset */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.gallery-item img {
width: 100%; /* Make the image responsive */
height: auto;
max-width: 300px; /* Limit maximum width */
display: block;
margin: 0 auto;
}
.caption {
margin-top: 10px;
font-size: 16px;
color: #333;
font-weight: bold;
}
.gallery-item {
width: 100%;
}
}
Explanation:
HTML Structure:
o We have a div with the class gallery to hold the image links.
o Inside the gallery, each image is wrapped in an anchor (<a>) tag, which acts as a
link. Each link contains an image (<img>) and a caption (<div class="caption">).
CSS Styling:
o The gallery class uses display: flex to arrange the items in a row. It also uses
gap: 20px to space the images evenly.
o The gallery-item class ensures that the links are block-level elements, so they
stack vertically on smaller screens.
o The images are made responsive with width: 100% and height: auto.
Additionally, max-width: 300px ensures the images do not stretch beyond a certain
size.
o A @media query is added to adjust the layout for screens smaller than 768px. In this
case, the layout switches to a column format where each image is stacked vertically.
How it works:
Notes:
Replace the src in the <img> tags with the actual URLs of your images.
Update the href in the anchor tags (<a href="...">) with the desired links.
Qns No.2
Program Statement: Create a Simple HTML Form to collect personal data
including the following form elements: Text field for name, Password field,
Email field, List of hobbies, Radio buƩons for gender, Checkboxes for
interests, Submit button.
Ans:-
To create a simple HTML form that collects personal data, including text fields for name, a
password field, an email field, a list of hobbies, radio buttons for gender, checkboxes for interests,
and a submit button, you can use the following HTML code:
HTML (index.html):
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Personal Data Form</title>
</head>
<body>
</form>
</body>
</html>
When the user fills out the form and clicks the "Submit" button, the form data will be sent to the
server (in this case, to the action URL "#", which means the form data is not actually sent
anywhere).
The required attribute ensures that the user cannot submit the form without filling out the
required fields.
The multiple attribute for the hobbies field and [] in the checkbox name attribute allows
multiple selections.
Customizations:
The action attribute of the <form> tag should be updated with a URL to which the form data
should be sent.
The method="POST" ensures that form data is sent securely.
This form can be further enhanced by adding CSS for styling and JavaScript for form validation if
needed.
Qns No.3
Program Statement: Create an HTML List with nested items with
the following structure:-
Beverages:-
Coffee
Tea
Black Tea
Green Tea
Milk
Ans:-
To create an HTML list with nested items based on the structure you provided (Beverages with
Coffee, Tea, Milk, and nested Tea types like Black Tea and Green Tea), you can use an unordered
list (<ul>) with nested <ul> tags for the sub-items.
HTML (index.html):
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Nested HTML List</title>
</head>
<body>
<h2>Beverages</h2>
<ul>
<!-- Coffee -->
<li>Coffee</li>
</body>
</html>
Explanation:
Output Structure:
Beverages
o Coffee
o Tea
Black Tea
Green Tea
o Milk
This will display a bulleted list with the nested structure for Tea.
Customization:
You can further style this list using CSS to customize the appearance (e.g., changing bullet styles,
adding indentation, etc.).
If you'd like to use numbered lists instead of bulleted ones, you can replace <ul> with <ol>
(ordered list).
Qns No.4
Program Statement: Create a college Web Page with specified elements:
Title of the page as "My College".
College name at the top in large text.
Address in smaller text.
List of courses offered in different colours and styles.
Scrolling text with a custom message.
College image at the bottom.
Ans:-
Here's the complete HTML and CSS code:
HTML (index.html):
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My College</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
</body>
</html>
CSS (styles.css):
css
Copy code
/* Basic reset */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.course-item {
font-size: 20px;
padding: 10px;
margin: 5px;
}
.course1 {
color: #3498DB; /* Blue */
font-style: italic;
}
.course2 {
color: #E74C3C; /* Red */
font-weight: bold;
}
.course3 {
color: #2ECC71; /* Green */
text-decoration: underline;
}
.course4 {
color: #F39C12; /* Orange */
text-transform: uppercase;
}
.course5 {
color: #9B59B6; /* Purple */
font-size: 22px;
}
marquee {
font-size: 20px;
color: #16A085;
}
.college-image img {
width: 80%;
max-width: 800px;
height: auto;
border: 5px solid #34495E;
}
Explanation:
2. College Name:
o The <h1> tag with the class college-name is used to display the college name in large
text at the top of the page. The text is styled with a large font size and centered.
3. College Address:
o The address is placed inside a <p> tag with the class college-address. It's styled with a
smaller font size and a gray color, centered on the page.
4. List of Courses:
o The list of courses is created with an unordered list (<ul>). Each course item is a list item
(<li>) with its own class. Each course is styled differently using CSS, with colors, font
styles, and text decorations applied.
5. Scrolling Text:
o The scrolling text is implemented using the <marquee> tag, which scrolls the message
from right to left. The text is styled with a larger font size and a custom color.
How to use:
Courses List: Each course has different styles applied. For example, "Computer Science" is blue and
italicized, "Business Administration" is red and bold, and so on.
Scrolling Text: The <marquee> tag is used for scrolling text, and you can modify the message inside
it to reflect your own message.
College Image: The src attribute of the <img> tag is set to a placeholder image URL. Replace this
with the actual URL of your college image.
Qns No.5
Program Statement:-Style a Table with CSS styling.
Design a table with three columns: City, Country, Population.
Add CSS to style borders, header background colour and alternate row
colours.
Ans:-
Here's the complete HTML and CSS code:
HTML (index.html):
html
Copy code
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Styled Table</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
</body>
</html>
CSS (styles.css):
css
Copy code
/* Reset default margins and padding */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* Table styling */
table {
width: 80%;
margin: 20px auto;
border-collapse: collapse; /* Merge table borders */
}
tbody tr:nth-child(even) {
background-color: #ffffff; /* White for even rows */
}
Explanation:
2. CSS Styling:
o Table Styling: The border-collapse: collapse; property removes the space between
borders, making the table look cleaner.
o Header Styling: The table header (<th>) has a green background (#4CAF50) and white
text. The text is aligned to the left with text-align: left;.
o Table Cell Styling: Each cell (<td>) has a light gray border (border: 1px solid #ddd)
and padding for spacing.
o Alternate Row Colors: The nth-child() selector is used to create alternate row colors:
Odd rows (nth-child(odd)) have a light gray background (#f2f2f2).
Even rows (nth-child(even)) have a white background.
o Hover Effect: When a user hovers over a row, the background color changes to a darker
gray (#ddd) for better user interaction.
How it works:
The table will display with alternating row colors for better readability.
The header will have a distinct background color to separate it from the data.
When you hover over a row, its background color will change slightly to indicate focus.
Customization:
You can easily adjust the colors, padding, and font styles by modifying the CSS properties.
The table width is set to 80% of the page width, but you can adjust this if needed to fit your layout
better.