Cover Image for How to Add a Login Form to an Image using HTML and CSS
78 views

How to Add a Login Form to an Image using HTML and CSS

To add a login form on top of an image using HTML and CSS, you can use a combination of absolute positioning and z-index. Here’s an example:

HTML:

HTML
<div class="login-container">
  <img src="your-image.jpg" alt="Background Image">
  <form class="login-form">
    <h2>Login</h2>
    <input type="text" placeholder="Username" required>
    <input type="password" placeholder="Password" required>
    <button type="submit">Login</button>
  </form>
</div>

CSS:

CSS
.login-container {
  position: relative;
}

.login-form {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1;
  background-color: rgba(255, 255, 255, 0.8);
  padding: 20px;
}

.login-form h2 {
  text-align: center;
}

.login-form input,
.login-form button {
  width: 100%;
  margin-bottom: 10px;
}

.login-form button {
  background-color: #007bff;
  color: #fff;
  border: none;
  padding: 10px;
  cursor: pointer;
}

In this example, we wrap both the image and the login form in a container div with the class “login-container”. We set the container’s position to relative.

The login form is given the class “login-form” and is positioned absolutely inside the container. It is centered vertically and horizontally using a combination of top, left, and transform properties. The z-index is set to 1 to place it on top of the image.

The login form itself consists of an h2 heading, two input fields for username and password, and a login button.

You can adjust the styles, positioning, and appearance according to your specific design requirements.

YOU MAY ALSO LIKE...

The Tech Thunder

The Tech Thunder

The Tech Thunder


COMMENTS