首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >bootstrap 4:巨型加速器中的居中内联表单

问bootstrap 4:巨型加速器中的居中内联表单
EN

Stack Overflow用户
提问于 2017-02-27 05:09:58
回答 1查看 28.3K关注 0票数 16

我在一个巨型加速器里有一个内联表单。我想把它放在中心。

我尝试在巨型加速器上使用text-align:center,它确实居中了巨型加速器中除内联表单元素之外的所有其他元素。所以我不知道这里出了什么问题。

这是HTML代码:

代码语言:javascript
复制
<div class="jumbotron" id="home">
  <h1 class="display-3">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>
  <form class="form-inline">
    <label class="sr-only" for="yourEmail">Email</label>
    <div class="input-group mb-2 mr-sm-2 mb-sm-0">
      <div class="input-group-addon">@</div>
      <input type="text" class="form-control" id="yourEmail" placeholder="Your Email">
    </div>
    <button type="button" class="btn btn-primary my-2 my-sm-0">Sign Up</button>
  </form>
</div>

这是CSS:

代码语言:javascript
复制
body{
  position: relative;
}

#home{
  background-image: url('../img/jumbotron-bkg-2.jpg');
  margin-top: 50px;
  text-align: center;
}

#yourEmail{
  width: 350px;
}

#about h2, #about-summary{
  text-align: center;
}

.card{
  margin-bottom: 30px;
}

.card img{
  height: 350px;
  width: 100%;
}

#cards-container{
  margin-bottom: 50px;
  padding: 20px 40px;
}

#download{
  text-align: center;
  padding-top: 100px;
  padding-bottom: 150px;
  background-color: #0afff2;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-27 05:23:33

在form上使用justify-content-center助手类。这将使用flex属性justify-content: center;居中显示内容

​

代码语言:javascript
复制
#home{
  background-image: url('../img/jumbotron-bkg-2.jpg');
  margin-top: 50px;
  text-align: center;
}
代码语言:javascript
复制
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<div class="jumbotron" id="home">
  <h1 class="display-3">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>
  <form class="form-inline justify-content-center">
    <label class="sr-only" for="yourEmail">Email</label>
    <div class="input-group mb-2 mr-sm-2 mb-sm-0">
      <div class="input-group-addon">@</div>
      <input type="text" class="form-control" id="yourEmail" placeholder="Your Email">
    </div>
    <button type="button" class="btn btn-primary my-2 my-sm-0">Sign Up</button>
  </form>
</div>

​

票数 41
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42474298

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档