无法将我的表格对齐到中心

时间:2018-03-17 14:44:39

标签: javascript css wordpress html5 twitter-bootstrap-4

代码:

<!doctype html>
<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 -->
    <title>Bootstrap</title>
    <link rel="stylesheet" href="css/bootstrap.min.css">

    <!--custom css-->
    <link rel="stylesheet" href="stylesheet.css">
</head>
<body>
    <section id="cover">
        <div id="cover-caption">
            <div class="container">
                <div class="col-sm-10 col-sm-offset-1">
                     <h1>Welcome to Bootstrap 4.0 !</h1>
                     <p>This is the platform that was created by twitter and is used in every website today</p>

                    <form action="" class="form-inline">
                       <div class="form-group">  <label class="sr-only">Name</label> <input type="text" class="form-control
form-control-lg" placeholder="Tanveer">
                       </div>


                        <div class="form-group">  <label class="sr-only">Email</label> <input type="text" class="form-control
form-control-lg" placeholder="tanveer@example.com ">
                       </div>
                       <button type="submit" class="btn btn-success btn-lg">Submit</button>
                     </form>


                </div>

              </div>


            </div>

          </section>

<nav class="navbar navbar-expand-lg navbar-dark bg-dark navbar-full"
id="nav-main">   <a class="navbar-brand" href="#">Bootstrap 4.0</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="#">Link</a>
      </li>
      <li class="nav-item dropdown">
        <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown"
aria-haspopup="true" aria-expanded="false">
          Dropdown
        </a>
        <div class="dropdown-menu" aria-labelledby="navbarDropdown">
          <a class="dropdown-item" href="#">Action</a>
          <a class="dropdown-item" href="#">Another action</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">Something else here</a>
        </div>
      </li>
      <li class="nav-item">
        <a class="nav-link disabled" href="#">Disabled</a>
      </li>
    </ul>
    <form class="form-inline my-2 my-lg-0">
      <input class="form-control mr-sm-2" type="search" placeholder="Search" aria-label="Search">
      <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
    </form>   </div> </nav>

        <!-- 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="js/bootstrap.min.js""></script>
 </body>
</html>

2 个答案:

答案 0 :(得分:0)

将html标记更改为中心的基本简单方法是使用align属性:

<form align="center">
 This sentence will be in the center!
</div>

请尝试更改此代码:

      <form action="" class="form-inline" >
            <div class="form-group">  <label class="sr-only">Name</label> <input type="text" class="form-control form-control-lg" placeholder="Tanveer">
            <div class="form-group">  <label class="sr-only">Email</label> <input type="text" class="form-control form-control-lg" placeholder="tanveer@example.com "> Submit
            </div>
            </div>
        </form>

要:

        <form action="" class="form-inline" align="center">
            <div class="form-group">  <label class="sr-only">Name</label> <input type="text" class="form-control form-control-lg" placeholder="Tanveer">
            <div class="form-group">  <label class="sr-only">Email</label> <input type="text" class="form-control form-control-lg" placeholder="tanveer@example.com "> Submit
            </div>
            </div>
        </form>

另一种方法是在CSS文件中添加"text-align: center;"

答案 1 :(得分:-1)

您可以使用下面的CSS将中心的表单与内容对齐。

npm install google-auth-library@0.* --save