Wie man ein: Formular auf dem Bild erstellt

Lernen Sie, wie man ein Formular auf einem vollständigen Bild mit CSS hinzufügt.

Formular auf dem Bild

Probieren Sie es selbst aus

Wie man ein Formular zu einem Bild hinzufügt

Schritt 1 - Fügen Sie HTML hinzu:

<div class="bg-img">
  <form action="/action_page.php" class="container">
    <h1>Einloggen</h1>
    <label for="email"><b>E-Mail</b></label>
    <input type="text" placeholder="Geben Sie Ihre E-Mail ein" name="email" required>
    <label for="psw"><b>Password</b></label>
    <input type="password" placeholder="Enter Password" name="psw" required>
    <button type="submit" class="btn">Login</button>
  </form>
</div>

Zweiter Schritt - Fügen Sie CSS hinzu:

body, html {
  height: 100%;
}
* {
  box-sizing: border-box;
}
.bg-img {
  /* 使用的图像 */
  background-image: url("img_nature.jpg");
  /* 控制图像的高度 */
  min-height: 380px;
  /* 将图像居中并适当地缩放 */
  background-position: center;
  background-repeat: no-repeat;
  background-size: cover;
  position: relative;
}
/* 为表单容器添加样式 */
.container {
  position: absolute;
  right: 0;
  margin: 20px;
  max-width: 300px;
  padding: 16px;
  background-color: white;
}
/* 全宽的输入字段 */
  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;
}
/* 为提交按钮设置样式 */
.btn {
  background-color: #04AA6D;
  color: white;
  padding: 16px 20px;
  border: none;
  cursor: pointer;
  width: 100%;
  Opacity: 0.9;
}
.btn:hover {
  Opacity: 1;
}

Probieren Sie es selbst aus