如何在jumbotron div的中心对齐形状?

时间:2018-03-05 19:57:35

标签: html css forms bootstrap-4

我试图在Bootstrap V4中复制模板,但无法在jumbotron div中存在的中心对齐表单。但是,其余文本在中心对齐。

我已从教程中复制了代码。此代码在本教程中工作正常,但我无法自己复制代码。只是想弄明白它出了什么问题。

这是代码。

@Service
public class AuthenticationHandler {

    @Autowired
    private UserDetailsManager userDetailsManager;
    @Autowired
    private Function userFactory;

    public void signUp(String email, String password) throws BadCredentialsException {
        UserDetails user = constructUser(email, password);
        userDetailsManager.createUser(user);
    }

    private UserDetails constructUser(String email, String password) {
        return (User) userFactory.apply(email, password);
    }
}

1 个答案:

答案 0 :(得分:0)

请尝试将您的新班级命名为:<form class="form-inline justify-content-center">

以下是示例:

&#13;
&#13;
<html lang="en">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">

    <title>Hello, world!</title>

    <style type="text/css">
        .jumbotron{
            background: url(pic.jpg);
            background-size: 100% 100%;
            text-align: center;

        } 

    </style>

  </head>
  <body>


    <!-- Nav Bar -->

    <nav class="navbar navbar-expand-lg navbar-light bg-light">
  <a class="navbar-brand" href="#">MyApp</a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>

  <div class="collapse navbar-collapse" id="navbarSupportedContent">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item active">
        <a class="nav-link" href="#">Home <span class="sr-only">(current)</span></a>
      </li>

      <li class="nav-item">
        <a class="nav-link" href="#">About</a>
      </li>

      <li class="nav-item">
        <a class="nav-link" href="#">Download The App</a>
      </li>

    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="email" placeholder="Email" aria-label="Email">
      <input class="form-control mr-sm-2" type="password" placeholder="Password" aria-label="Password">
      <button class="btn btn-success my-2 my-sm-0" type="submit">Login</button>
    </form>
  </div>
</nav>


    <!-- Nav Bar -->

   <!-- JumboTron Header -->


<div class="jumbotron">
  <h1 class="display-4">My Awesome App!</h1>
  <p class="lead">This is why YOU should download this fantastic app!.</p>
  <hr class="my-4">
  <p>Want to know more? Join our mailing list!</p>

  <!-- inline form -->

  <form class="form-inline justify-content-center">
    <div class="form-group">
     <label class="sr-only" for="email">Email address</label>
       <div class="input-group">
           <div class="input-group-text">@</div>
            <input type="email" class="form-control" id="email" placeholder="Your email">

       </div>    


    </div>  
  <button type="submit" class="btn btn-primary">Sign up</button>      

  </form>

  <!-- inline form -->


</div>

    <!--JumboTron Header -->



    <!-- Optional JavaScript -->
    <!-- jQuery first, then Popper.js, then Bootstrap JS -->
    <script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
  </body>
</html>
&#13;
&#13;
&#13;