引导程序居中

时间:2018-08-05 05:47:23

标签: html css bootstrap-4

我一直在使用引导程序,现在我在使Im创建的内容居中时遇到了一些麻烦,第一个问题是无法将右侧导航栏项垂直居中,它只是超过了中心导航栏的中心线该导航栏,第二个导航栏是用不同的类包装的div中的登录表单,我一直试图使其水平居中,为什么导航栏的右侧项必须为无序列表显示一个点当左边的项目不显示而只是更改div的类时。如果可能的话,我希望对此有所帮助。

image 这里的代码:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Member area</title>
  <link rel="stylesheet" href="style.css">
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>

<body>
  <!-- NAV BAR -->
  <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <a class="navbar-brand" href="#">PlaceHolder</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">
          <a class="nav-link" href="#">Home
                        <span class="sr-only">(current)</span>
                    </a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">About me</a>
        </li>
      </ul>

      <ul class "navbar-nav ml-auto">
        <li class="nav-item">
          <a class="nav-link" href="#">Member Area</a>
        </li>
      </ul>

    </div>
  </nav>
  <!--END OF NAV BAR-->

  <!-- LOG IN FORM-->
  <form action="">
    <div class="form-group row">
      <div class="container text-center">
        <div class="ocol-lg-4 col-lg-offset-4">
          <div class="col-3">
            <label for="username">Username</label>
            <input type="username" class="form-control" id="username" placeholder="Enter username">
          </div>
          <div class="col-3">
            <label for="password">Password</label>
            <input type="password" class="form-control" id="password" placeholder="Enter password">
          </div>
          <div class="col-3">
            <input type="submit" class="form-control" id="submit" value="Submit">
          </div>
        </div>
      </div>
    </div>




  </form>

  <!-- END OF LOGIN FORM-->
</body>

</html>

2 个答案:

答案 0 :(得分:0)

问题是您在navbar崩溃时使用了两个ul,请尝试仅使用一个ul,然后再添加一个具有属性li的空flex: 1,此空li将增长以填充空间在元素之间,将它们推向侧面。

答案 1 :(得分:0)

模板中有很多问题。

首先,在<ul class "navbar-nav ml-auto">中的class属性之后缺少“ =”符号

使用offset-lg-4代替col-lg-offset-4

应在row元素内使用“ container”,以更改容器div的位置。

container元素中删除文本中心

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Member area</title>
  <link rel="stylesheet" href="style.css">
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.2.0/css/all.css" integrity="sha384-hWVjflwFxL6sNzntih27bfxkr27PmbbK/iSvJ+a4+0owXq79v+lsFkW54bOGbiDQ" crossorigin="anonymous">
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
</head>

<body>
  <!-- NAV BAR -->
  <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
    <a class="navbar-brand" href="#">PlaceHolder</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">
          <a class="nav-link" href="#">Home
                        <span class="sr-only">(current)</span>
                    </a>
        </li>
        <li class="nav-item">
          <a class="nav-link" href="#">About me</a>
        </li>
      </ul>

      <ul class="navbar-nav ml-auto">
        <li class="nav-item">
          <a class="nav-link" href="#">Member Area</a>
        </li>
      </ul>

    </div>
  </nav>
  <!--END OF NAV BAR-->

  <!-- LOG IN FORM-->
  <div class="container">
    <form action="">
      <div class="form-group">

        <div class="row">
          <div class="col-lg-4 offset-lg-4 text-center">

            <div class="">
              <label for="username">Username</label>
              <input type="username" class="form-control" id="username" placeholder="Enter username">
            </div>
            <div class="">
              <label for="password">Password</label>
              <input type="password" class="form-control" id="password" placeholder="Enter password">
            </div>
            <div class="">
              <input type="submit" class="form-control" id="submit" value="Submit">
            </div>
          </div>
        </div>
      </div>

    </form>
  </div>

  <!-- END OF LOGIN FORM-->
</body>

</html>