Cách tạo: Biểu mẫu trên hình ảnh

Học cách sử dụng CSS để thêm biểu mẫu vào hình ảnh toàn màn hình.

Biểu mẫu trên hình ảnh

Thử ngay

Cách thêm biểu mẫu vào hình ảnh

Bước 1 - Thêm HTML:

<div class="bg-img">
  <form action="/action_page.php" class="container">
    <h1>Đăng nhập</h1>
    <label for="email"><b>Email</b></label>
    <input type="text" placeholder="Nhập Email" name="email" required>
    <label for="psw"><b>Mật khẩu</b></label>
    <input type="password" placeholder="Nhập mật khẩu" name="psw" required>
    <button type="submit" class="btn">Đăng nhập</button>
  </form>
</div>

Bước 2 - Thêm CSS:

body, html {
  height: 100%;
}
* {
  box-sizing: border-box;
}
.bg-img {
  /* Hình ảnh được sử dụng */
  background-image: url("img_nature.jpg");
  /* Kiểm soát chiều cao của hình ảnh */
  min-height: 380px;
  /* Đặt hình ảnh ở giữa và phóng to hợp lý */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  position: relative;
}
/* Thiết lập樣式 cho khung biểu mẫu */
.container {
  position: absolute;
  right: 0;
  margin: 20px;
  max-width: 300px;
  padding: 16px;
  background-color: white;
}
/* Champs d'entrée de largeur complète */
  input[type=text], input[type=password] {
  width: 100%;
  padding: 15px;
  margin: 5px 0 22px 0;
  border: none;
  background: #f1f1f1;
}
input[type=text]:focus, input[type=password]:focus {
  background-color: #ddd;
  outline: none;
}
/* Thiết lập樣式 cho nút gửi */
.btn {
  background-color: #04AA6D;
  color: white;
  padding: 16px 20px;
  border: none;
  cursor: pointer;
  width: 100%;
  opacity: 0.9;
}
.btn:hover {
  opacity: 1;
}

Thử ngay