【问题标题】:How to align container and labels with checkbox in Bootstrap?如何将容器和标签与 Bootstrap 中的复选框对齐?
【发布时间】:2020-12-05 04:05:59
【问题描述】:

我想实现这一点。这是一个点击弹出窗口。

到目前为止,这就是我所做的。

如您所见,它占用了所有页面,我不知道为什么,并且无法将标签与复选框对齐,因为标签出现在复选框下方,我无法移动它们。我真的很想提出一些建议,这个想法是使用引导程序。我尝试阅读一些文档,但由于我刚刚开始,我真的很难理解所有内容。

CSS:

body{
    padding:0;
    margin:0;
  }
  
  .signupContainer{
    height:100%;
    position:absolute;
    overflow:hidden;
    background-color: white;
    box-shadow: 15px 9px 26px rgba(0, 0, 0, 0.2);
    border-radius: 20px;
    margin: 0 auto;
  }

  .box{
    position:absolute;
    height:100%;
    width:50%;
    margin-top: 55px;
    font-family: 'Poppins', sans-serif;     
    padding-bottom: 140px;
  }

  .box h1{
    text-align:center;
    margin: 0 auto;
    font-size:30px;
    margin-bottom: 20px;
  }
  
  .box input{
    font-family: 'Poppins', sans-serif;
    display:block;
    width:300px;
    margin:0px auto;
    padding:5px;
    text-align: center;
    background: #F8F8F8;
    color:#fff;
    border:0;
    border-radius: 20px;
    margin-bottom: 20px
  }
  .box input:focus,.box input:active,.box button:focus,.box button:active{
    outline:none;
  }

  .box label {
      font-family: 'Poppins', sans-serif;
  }

  .box button{
    background: #FE6047;
    border:0;
    color:#fff;
    padding:5px;
    font-size:20px;
    width:300px;
    margin:20px auto;
    display:block;
    cursor:pointer;
    border-radius: 20px;
  }
  .box button:active{
    background:#27ae60;
  }
  .box p{
    font-size:14px;
    text-align:center;
  }
  .box p span{
    cursor:pointer;
    color:#666;
  }

  input[type=checkbox] {
    margin: 2px 0 0;
    align-self: flex-start;
}

HTML:

    <div class="signupContainer col-6">
      <div class="box col-12">
        <h1 class="col">Sign up</h1>
        <input type="text"  class="col" placeholder="Usuario"/>
        <input type="email" class="col" placeholder="Email"/>
        <input type="text"  class="col" placeholder="Pais"/>
        <input type="password" class="col" placeholder="Contraseña"/>
        <input type="password" class="col" placeholder="Repite contraseña"/>
         <label for="seller" class="checkbox-inline"><input type="checkbox" id="seller" >Vendedor</label>
       <label for="buyer" class="checkbox-inline"><input type="checkbox" id="buyer" > Comprador</label>
        <button class="col">Sign</button>
      </div>
    </div>

谢谢!

【问题讨论】:

    标签: html css web bootstrap-4 responsive-design


    【解决方案1】:

    试试这个:

    HTML:

    <div class="ContainerSignUp">
      <div class="ContainerHeaderBG"></div>
      <div class="signupContainer col-6">
        <div class="box col-12">
          <h1 class="col">Sign up</h1>
          <input type="text"  class="col" placeholder="Usuario"/>
          <input type="email" class="col" placeholder="Email"/>
          <input type="text"  class="col" placeholder="Pais"/>
          <input type="password" class="col" placeholder="Contraseña"/>
          <input type="password" class="col" placeholder="Repite contraseña"/>
          <label for="seller" class="checkbox-inline">
            <input type="checkbox" id="seller">Vendedor
          </label>
          <label for="buyer" class="checkbox-inline">
            <input type="checkbox" id="buyer">Comprador
          </label>
          <button class="col">Sign</button>
        </div>
      </div>
    </div>
    

    CSS:

    body {
        padding: 0;
        margin: 0;
    }
    
    .ContainerSignUp {
      position: relative;
      background: blue;
    }
    
    .ContainerHeaderBG {
      width: 100%;
      height: 200px;
      background: green;
    }
    
    .signupContainer {
      width: 500px;
      max-width: 90%;
      top: 100px;
      left: 50%;
      transform: translateX(calc(-50% + 0.1px));
        position: absolute;
        overflow: hidden;
        background-color: white;
        box-shadow: 15px 9px 26px rgba(0, 0, 0, 0.2);
        border-radius: 20px;
        margin: 0 auto;
    }
    
    .box h1 {
        text-align: center;
        margin: 100px auto 0;
        font-size: 30px;
        margin-bottom: 20px;
    }
    
    .box input {
        font-family: 'Poppins', sans-serif;
        display: block;
        width: 80%;
        margin: 0px auto;
        padding: 5px 20px;
        text-align: left;
        background: #F8F8F8;
        color: #fff;
        border: 0;
        border-radius: 20px;
        margin-bottom: 20px;
      color: #000;
    }
    
    .box input:focus,
    .box input:active,
    .box button:focus,
    .box button:active {
        outline: none;
    }
    
    .box label {
        font-family: 'Poppins', sans-serif;
      display: block;
      width: 80%;
      margin: auto;
    }
    
    .box button {
        background: #FE6047;
        border: 0;
        color: #fff;
        padding: 5px;
        font-size: 20px;
        width: 300px;
        margin: 20px auto;
        display: block;
        cursor: pointer;
        border-radius: 20px;
    }
    
    .box button:active {
        background: #27ae60;
    }
    
    .box p {
        font-size: 14px;
        text-align: center;
    }
    
    .box p span {
        cursor: pointer;
        color: #666;
    }
    
    input[type=checkbox] {
        margin: 2px 0 0;
        align-self: flex-start;
    }
    
    
    /* Modification */
    
    input#seller,
    input#buyer {
        display: inline;
        width: 11px;
        margin-right: 10px;
    }
    

    我在 CodePen 中发布的示例:
    CodePen Example

    【讨论】:

    • 它变得更好了,标签出现在复选框旁边,但框的顶部似乎与窗口相连
    • @YomiraMartínez 我以前不懂这个问题,现在试试吧!我将 CodePen 演示的链接放在答案的末尾。
    猜你喜欢
    • 2014-01-22
    • 2015-01-02
    • 2021-02-25
    • 2023-01-24
    • 1970-01-01
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多