使用CSS网格布局,如何移动外壳密码旁边的“复选框”?

olj*_*ljo 5 html css css-grid

我是编程新手(使用在线课程学习)

我只是在测试并获得对 CSS 的“感觉”,我现在已经用了 2 天时间来尝试理解 CSS 网格,但是我在尝试解决这个小问题时遇到了困难。

首先,使用 CSS 进行布局有不同的方法,有推荐的方法吗?grid 是要走的路,还是 flex?

我正在尝试为我的一个项目设计登录表单,我快到了,但我不知道如何将复选框从一列移动到另一列。

图片显示我的意思。

我的 HTML:

.grid-container {
  display: grid;
  padding: 1em;
  justify-content: center;
  align-content: center;
}

form {
  background: #2DA1A8;
  padding: 2em;
  display: grid;
  grid-template-columns: auto auto;
}
Run Code Online (Sandbox Code Playgroud)
<body>
<div class="grid-container">
    <form action="">
        <label for="username" class="user-name">Brukernavn</label>
        <input type="text" class="username">

        <label for="password" class="pass-word">Passord</label>
        <input type="password" class="password">

        <button class="login">Logg inn</button>

        <label for="rpass" class="rem-pass">Husk passord</label>

        <input type="checkbox" class="remember">
        <label for="fpass" class="forgot">Glemt <a href="#">passord?</a></label>
      </form>
</div>  
</body>
Run Code Online (Sandbox Code Playgroud)

Sta*_*ley 1

<div>在您的复选框和标签周围放置一个:

为了便于将来参考,我强烈建议您观看 firebase 的此视频: https://www.youtube.com/watch?v=uuOXPWCh -6o

在此输入图像描述

.grid-container {
    display: grid;
    padding: 1em;
    justify-content: center;
    align-content: center;
}

form {
    background: #2da1a8;
    padding: 2em;
    display: grid;
    grid-template-columns: auto auto;
}
Run Code Online (Sandbox Code Playgroud)
  <form action="">
        <div class="grid-container">
          <label for="username" class="user-name">Brukernavn</label>
          <input type="text" class="username">
  
          <label for="password" class="pass-word">Passord</label>
          <input type="password" class="password">
  
          <button class="login">Logg inn</button>
  <div>

    <label for="rpass" class="rem-pass">Husk passord</label>
    <input type="checkbox" class="remember">
  </div>

          <label for="fpass" class="forgot">Glemt <a href="#">passord?</a></label>
        </div>  
      </form>
Run Code Online (Sandbox Code Playgroud)


唯一的改变是:

  • 在表单内移动网格 div
  • div 中的环绕标签和复选框

直到!