0% found this document useful (0 votes)
3 views2 pages

CSS Dropdown and Form Example

The document provides an explanation and examples of CSS dropdown menus and forms. It includes HTML and CSS code for creating a dropdown menu that appears on hover and a form for collecting user input. The examples demonstrate styling and functionality for both components.

Uploaded by

gokila.digitaly
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)
3 views2 pages

CSS Dropdown and Form Example

The document provides an explanation and examples of CSS dropdown menus and forms. It includes HTML and CSS code for creating a dropdown menu that appears on hover and a form for collecting user input. The examples demonstrate styling and functionality for both components.

Uploaded by

gokila.digitaly
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

CSS Dropdown and Form - Explanation and

Example
1. CSS Dropdown A dropdown is a hidden list that appears when a button or menu item is hovered
or clicked. Example HTML & CSS:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Dropdown Example</title>
<style>
.dropdown {
position: relative;
display: inline-block;
}
.dropbtn {
background-color: #4CAF50;
color: white;
padding: 10px 20px;
font-size: 16px;
border: none;
cursor: pointer;
}
.dropdown-content {
display: none;
position: absolute;
background-color: white;
min-width: 160px;
box-shadow: 0px 8px 16px rgba(0,0,0,0.2);
z-index: 1;
}
.dropdown-content a {
color: black;
padding: 10px 15px;
text-decoration: none;
display: block;
}
.dropdown-content a:hover {
background-color: #f1f1f1;
}
.dropdown:hover .dropdown-content {
display: block;
}
.dropdown:hover .dropbtn {
background-color: #3e8e41;
}
</style>
</head>
<body>
<h2>CSS Dropdown Example</h2>
<div class="dropdown">
<button class="dropbtn">Menu</button>
<div class="dropdown-content">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
</div>
</div>
</body>
</html>

2. CSS Form Forms are used to collect user input such as name, email, and message. Example
HTML & CSS:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CSS Form Example</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #f5f5f5;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.form-container {
background-color: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0px 0px 10px rgba(0,0,0,0.2);
width: 300px;
}
.form-container h2 {
text-align: center;
margin-bottom: 20px;
}
label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
input[type="text"],
input[type="email"],
textarea {
width: 100%;
padding: 8px;
margin-bottom: 15px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}
input[type="submit"] {
width: 100%;
background-color: #4CAF50;
color: white;
padding: 10px;
border: none;
border-radius: 5px;
cursor: pointer;
font-size: 16px;
}
input[type="submit"]:hover {
background-color: #45a049;
}
</style>
</head>
<body>
<div class="form-container">
<h2>Contact Us</h2>
<form>
<label for="name">Name:</label>
<input type="text" id="name" placeholder="Enter your name">

<label for="email">Email:</label>
<input type="email" id="email" placeholder="Enter your email">

<label for="message">Message:</label>
<textarea id="message" rows="4" placeholder="Enter your message"></textarea>

<input type="submit" value="Submit">


</form>
</div>
</body>
</html>

You might also like