当我尝试使用容器流体时,居中窗体向左移动.如何使其居中? [英] When I try to use container-fluid centered form is moving to the left. How to keep it in the center?

查看:75
本文介绍了当我尝试使用容器流体时,居中窗体向左移动.如何使其居中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在全屏上给渐变色时,我尝试使用容器流体,但是带有居中位置的卡片的表格向左移动.这是代码:

When I give a gradient color to the full screen I tried to use container-fluid for that but the form with the card which was centered moved left. Here is the code:

<div class="container-fluid form">
    <div class="row form-row">
      <div class="col-sm-9 col-md-7 col-lg-5 mx-auto signinform">
        <div class="card card-signin my-5">
          <div class="card-body">
            <h5 class="card-title text-center">Sign In</h5>
            <form class="form-signin">
              <div class="form-label-group">
                <input type="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
                <label for="inputEmail">Email address</label>
              </div>
              <div class="form-label-group">
                <input type="password" id="inputPassword" class="form-control" placeholder="Password" required>
                <label for="inputPassword">Password</label>
              </div>
              <div class="custom-control custom-checkbox mb-3">
                <input type="checkbox" class="custom-control-input" id="customCheck1">
                <label class="custom-control-label" for="customCheck1">Remember password</label>
              </div>
              <button class="btn btn-lg btn-primary btn-block text-uppercase" type="submit">Sign in</button>
              <hr class="my-4">
              <button class="btn btn-lg btn-google btn-block text-uppercase" type="submit"><i class="fab fa-google mr-2"></i> Sign in with Google</button>
              <button class="btn btn-lg btn-facebook btn-block text-uppercase" type="submit"><i class="fab fa-facebook-f mr-2"></i> Sign in with Facebook</button>
            </form>
          </div>
        </div>
      </div>
    </div>
  </div>

CSS

:root {
  --input-padding-x: 1.5rem;
  --input-padding-y: .75rem;
}

.container-fluid,.row {
  height: 100vh;

  text-align: center;
 background: #FF512F;  /* fallback for old browsers */
background: -webkit-linear-gradient(to right, #DD2476, rgb(47, 120, 255));  /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #DD2476, rgb(47, 95, 255)); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */

}

.card.card-signin.my-5 {
  background-color: rgba(255, 255, 255, 0.6);
}



.col-sm-9.col-md-7.col-lg-5.mx-auto {
  align-items: center;
  display: flex;
}

.card-signin {
  border: 0;
  border-radius: 1rem;
  box-shadow: 0 0.5rem 1rem 0 rgba(0, 0, 0, 0.1);
}

.card-signin .card-title {
  margin-bottom: 2rem;
  font-weight: 300;
  font-size: 1.5rem;
}

.card-signin .card-body {
  padding: 2rem;
}

.form-signin {
  width: 100%;
}

.form-signin .btn {
  font-size: 80%;
  border-radius: 5rem;
  letter-spacing: .1rem;
  font-weight: bold;
  padding: 1rem;
  transition: all 0.2s;
}

.form-label-group {
  position: relative;
  margin-bottom: 1rem;
}

.form-label-group input {
  border-radius: 2rem;
}

.form-label-group>input,
.form-label-group>label {
  padding: var(--input-padding-y) var(--input-padding-x);
}

.form-label-group>label {
  position: absolute;
  top: 0;
  left: 0;
  display: block;
  width: 100%;
  margin-bottom: 0;
  /* Override default `<label>` margin */
  line-height: 1.5;
  color: #495057;
  border: 1px solid transparent;
  border-radius: .25rem;
  transition: all .1s ease-in-out;
}

.form-label-group input::-webkit-input-placeholder {
  color: transparent;
}

.form-label-group input:-ms-input-placeholder {
  color: transparent;
}

.form-label-group input::-ms-input-placeholder {
  color: transparent;
}

.form-label-group input::-moz-placeholder {
  color: transparent;
}

.form-label-group input::placeholder {
  color: transparent;
}

.form-label-group input:not(:placeholder-shown) {
  padding-top: calc(var(--input-padding-y) + var(--input-padding-y) * (2 / 3));
  padding-bottom: calc(var(--input-padding-y) / 3);
}

.form-label-group input:not(:placeholder-shown)~label {
  padding-top: calc(var(--input-padding-y) / 3);
  padding-bottom: calc(var(--input-padding-y) / 3);
  font-size: 12px;
  color: #777;
}

.btn-google {
  color: white;
  background-color: #ea4335;
}

.btn-facebook {
  color: white;
  background-color: #3b5998;
}

在这里我不能使用body标签,因为它是Angular项目中的一个组件.如何将表单保持在中心而不是向左移动?怎么了?

I can't use body tag here since it's a component inside the Angular project. How can I keep the form in the center instead of moving left? What is wrong?

推荐答案

使用margin: 0 auto;将元素居中

.card.card-signin.my-5 {
  background-color: rgba(255, 255, 255, 0.6);
  margin: 0 auto;
}

可用测试

这篇关于当我尝试使用容器流体时,居中窗体向左移动.如何使其居中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆