html - 将 Bootstrap 表单组输入字段居中并使其变小

标签 html css twitter-bootstrap

我目前正在尝试实现您在下面看到的设计:

enter image description here

除了输入字段和按钮的大小外,一切正常。我正在使用 Boostrap。

HTML:

  <div className='jumbotron text-center'>
    <div className='container'>
      <h1 id='hero-questions-h1'>What’s your name?</h1>
    </div>

    <div className='container'>
      <div class="col-sm-4 text-center">
        <div className="form-group input-group-lg">
          <input type="text" className="form-control"></input>
        </div>
        <button type="button" id="continue-btn" className="btn btn-success btn-block">Continue</button>
      </div>
    </div>

      <div className='container'>
        <h2 id='tip'>
          Tip! You will get motivational playlists, stories, posters and much more
        </h2>
      </div>

    <footer className="footer">
      <div className="container">
        <p id="social-proof" className="text-center">“Must have for every ambitious athlete!”</p>
        <p id="social-proof-tagline" className="text-center">Anders Hasselstrøm, Deca Ironman (10x)</p>
      </div>
    </footer>
  </div>

CSS:

.jumbotron {
  height: 100vh;
  margin-bottom: 0px !important;
  background-image: url("bg-hero-v2.png");
  background-size: cover;
}

#hero-h1 {
  color: white;
  font-family: 'Roboto', sans-serif;
  font-weight: 700;
  font-size: 60px;
  padding-top: 10%;
}

#hero-h2 {
  color: #ECECEC;
  font-family: 'Roboto', sans-serif;
  font-weight: 300;
  font-size: 20px;
  margin-top: 30px;
  line-height: 40px;
  padding-bottom: 40px;
}

#hero-questions-h1 {
  color: white;
  font-family: 'Roboto', sans-serif;
  font-weight: 700;
  font-size: 60px;
  padding-top: 10%;
  padding-bottom: 30px;
}

.btn-success {
  background-color: #66B878 !important;
}

.form-control {
  background-color: transparent !important;
  color: white !important;
}

#signup-btn {
  padding-left: 40px;
  padding-right: 40px;
  padding-top: 15px;
  padding-bottom: 15px;
}

#continue-btn {
  height: 60px;
  font-size: 18px;
}

#social-proof {
  color: white;
  font-family: 'Roboto', sans-serif;
  font-weight: 500;
  font-size: 18px;
  font-style: italic;
}

#social-proof-tagline {
  color: white;
  font-family: 'Roboto', sans-serif;
  font-weight: 100;
  font-size: 16px;
}

#tip {
  color: #ECECEC;
  font-family: 'Roboto', sans-serif;
  font-weight: 300;
  font-size: 16px;
  margin-top: 30px;
}

.footer {
  padding-top: 20px;
  padding-bottom: 20px;
  position: fixed;
  bottom: 0;
  width: 100%;
  background-color: black;
  opacity: 0.6;

}

如您所见,我当前的实现如下所示:

enter image description here

最佳答案

DOM 元素使用 class而不是 className分配 CSS 类(您可能会将其与 JS .className 属性混淆)。要按照您的喜好放置字段,我建议您利用 Bootstrap 网格 col-x-offset-x options将列从 .row 的左侧偏移定位

为了正确定位,记得放置一个.row列周围的元素,以及 .container 之间的元素.另外,input元素是自动关闭的(即你不需要尾随 </input> )

HTML

<div class='jumbotron text-center'>
    <div class='container'>
        <h1 id='hero-questions-h1'>What’s your name?</h1>
    </div>

    <div class='container'>
        <div class="row">
            <div class="col-sm-offset-3 col-sm-6 text-center">
                <div class="form-group input-group-lg">
                    <input type="text" class="form-control" />
                </div>
                <button type="button" id="continue-btn" class="btn btn-success btn-block">Continue</button>
            </div>
        </div>
    </div>

    <div class='container'>
        <h2 id='tip'>
          Tip! You will get motivational playlists, stories, posters and much more
        </h2>
    </div>

    <footer class="footer">
        <div class="container">
            <p id="social-proof" class="text-center">“Must have for every ambitious athlete!”</p>
            <p id="social-proof-tagline" class="text-center">Anders Hasselstrøm, Deca Ironman (10x)</p>
        </div>
    </footer>
</div>

JSFIDDLE

关于html - 将 Bootstrap 表单组输入字段居中并使其变小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41606453/

相关文章:

html - 我想让这个响应时间轴有 6 个步骤

javascript - Bootstrap 轮播在我的固定顶部导航上滚动

javascript - Element.insertAdjacentHTML 与::before 和::after Bootstrap 类不兼容

javascript - 如何每 X 秒更改一次背景图像?

jquery - 如何在表格的div中垂直居中对齐文本?

javascript - 如何在 React 的嵌套组件场景中将内容对齐到中心

javascript - 在容器 div 中分别居中 2 个 div

html - 使大像素图像适合给定的宽度和高度

javascript - 按下按钮即可在网站其余部分的顶部播放视频

jquery - 通过 Ajax post 加载 Bootstrap 选择选项