【问题标题】:Align 3 buttons on same row with Bootstrap将同一行上的 3 个按钮与 Bootstrap 对齐
【发布时间】:2016-09-23 21:46:41
【问题描述】:

对于下面标题为“操作”的三个橙色按钮,我尝试将它们水平地内联显示在同一行上(均匀分布在行中)。我把它们放在一个“btn-group”中,我认为它会自动处理这个问题。

我需要使用 col 大小来添加十二个吗?如何将三个按钮均匀分布在同一行?

“btn-group”中的三个按钮可以在我的代码底部找到。这是我的代码:

<div class="c-form-container section-container section-container-image-bg">
  <div class="container">

    <div class="row">
      <div class="col-sm-8 col-sm-offset-2 c-form section-description wow fadeIn">
        <h1>Happy <strong>Hour</strong></h1>
        <p>If you win, you drink for free, and your friends half off!</p>
      </div>
    </div>

    <div class="row">
      <div class="col-sm-6 col-sm-offset-3 c-form-box wow fadeInUp">

        <div class="c-form-top">
          <div class="c-form-top-left">
            <h3>Sign Up</h3>
            <p>Fill in the form below to win a happy hour:</p>
          </div>
          <div class="c-form-top-right">
            <div class="c-form-top-right-icon">
              <i class="fa fa-paper-plane"></i>
            </div>
          </div>
        </div>

        <div class="c-form-bottom">
          <form role="form" action="assets/contact.php" method="post">
            <div class="form-group">
              <label for="c-form-name">
                <span class="label-text">Name:</span>
                <span class="contact-error"></span>
              </label>
              <input type="text" name="name" placeholder="First & Last Name" class="c-form-name form-control" id="c-form-name">
            </div>

            <div class="form-group">
              <label for="c-form-birthday">
                <span class="label-text">Birthday:</span>
                <span class="contact-error"></span>
              </label>
              <input type="text" name="birthday" placeholder="Your Birthday" class="c-form-birthday form-control" id="c-form-birthday">
            </div>

            <div class="form-group">
              <label for="c-form-email">
                <span class="label-text">Email:</span>
                <span class="contact-error"></span>
              </label>
              <input type="text" name="email" placeholder="Your Email Address" class="c-form-email form-control" id="c-form-email">
            </div>

            <div class="form-group">
              <label for="c-form-cell">
                <span class="label-text">Cell Phone:</span>
                <span class="contact-error"></span>
              </label>
              <input type="text" name="cell" placeholder="Your Cell Phone Number" class="c-form-cell form-control" id="c-form-cell">
            </div>


            <div class="btn-group">

              <button type="button" data-toggle="dropdown" class="btn btn-default dropdown-toggle">Action <span class="caret"></span>
              </button>
              <ul class="dropdown-menu">
                <li><a href="#">Action</a>
                </li>
                <li><a href="#">Another action</a>
                </li>
                <li><a href="#">Separated link</a>
                </li>
              </ul>

              <button type="button" data-toggle="dropdown" class="btn btn-default dropdown-toggle">Action <span class="caret"></span>
              </button>
              <ul class="dropdown-menu">
                <li><a href="#">Action</a>
                </li>
                <li><a href="#">Another action</a>
                </li>
                <li><a href="#">Separated link</a>
                </li>
              </ul>

              <button type="button" data-toggle="dropdown" class="btn btn-default dropdown-toggle">Action <span class="caret"></span>
              </button>
              <ul class="dropdown-menu">
                <li><a href="#">Action</a>
                </li>
                <li><a href="#">Another action</a>
                </li>
                <li><a href="#">Separated link</a>
                </li>
              </ul>

            </div>


            <button type="submit" class="btn">Submit Information</button>

          </form>
        </div>
      </div>
    </div>
  </div>
</div>

这是我的 css 文件:

body {

  font-family: 'Roboto', sans-serif;

  font-size: 16px;

  font-weight: 300;

  color: #888;

  line-height: 30px;

  text-align: center;

}

strong {

  font-weight: 500;

}

a,

a:hover,

a:focus {

  color: #de615e;

  text-decoration: none;

  -o-transition: all .3s;

  -moz-transition: all .3s;

  -webkit-transition: all .3s;

  -ms-transition: all .3s;

  transition: all .3s;

}

h1,

h2 {

  margin-top: 10px;

  font-size: 38px;

  font-weight: 100;

  color: #555;

  line-height: 50px;

}

h3 {

  font-size: 22px;

  font-weight: 300;

  color: #555;

  line-height: 30px;

}

img {

  max-width: 100%;

}

::-moz-selection {

  background: #de615e;

  color: #fff;

  text-shadow: none;

}

::selection {

  background: #de615e;

  color: #fff;

  text-shadow: none;

}

.btn-link-1 {

  display: inline-block;

  height: 50px;

  margin: 5px;

  padding: 16px 20px 0 20px;

  background: #de615e;

  font-size: 16px;

  font-weight: 300;

  line-height: 16px;

  color: #fff;

  -moz-border-radius: 4px;

  -webkit-border-radius: 4px;

  border-radius: 4px;

}

.btn-link-1:hover,

.btn-link-1:focus,

.btn-link-1:active {

  outline: 0;

  opacity: 0.6;

  color: #fff;

}

.btn-link-1.btn-link-1-facebook {

  background: #4862a3;

}

.btn-link-1.btn-link-1-twitter {

  background: #55acee;

}

.btn-link-1.btn-link-1-google-plus {

  background: #dd4b39;

}

.btn-link-1 i {

  padding-right: 5px;

  vertical-align: middle;

  font-size: 20px;

  line-height: 20px;

}

.btn-link-2 {

  display: inline-block;

  height: 50px;

  margin: 5px;

  padding: 15px 20px 0 20px;

  background: rgba(0, 0, 0, 0.3);

  border: 1px solid #fff;

  font-size: 16px;

  font-weight: 300;

  line-height: 16px;

  color: #fff;

  -moz-border-radius: 4px;

  -webkit-border-radius: 4px;

  border-radius: 4px;

}

.btn-link-2:hover,

.btn-link-2:focus,

.btn-link-2:active,

.btn-link-2:active:focus {

  outline: 0;

  opacity: 0.6;

  background: rgba(0, 0, 0, 0.3);

  color: #fff;

}

/***** Top content *****/

.inner-bg {

  padding: 100px 0 170px 0;

}

.top-content .text {

  color: #fff;

}

.top-content .text h1 {

  color: #fff;

}

.top-content .description {

  margin: 20px 0 10px 0;

}

.top-content .description p {

  opacity: 0.8;

}

.top-content .description a {

  color: #fff;

}

.top-content .description a:hover,

.top-content .description a:focus {

  border-bottom: 1px dotted #fff;

}

.form-box {

  margin-top: 35px;

}

.form-top {

  overflow: hidden;

  padding: 0 25px 15px 25px;

  background: #444;

  background: rgba(0, 0, 0, 0.35);

  -moz-border-radius: 4px 4px 0 0;

  -webkit-border-radius: 4px 4px 0 0;

  border-radius: 4px 4px 0 0;

  text-align: left;

}

.form-top-left {

  float: left;

  width: 75%;

  padding-top: 25px;

}

.form-top-left h3 {

  margin-top: 0;

  color: #fff;

}

.form-top-left p {

  opacity: 0.8;

  color: #fff;

}

.form-top-right {

  float: left;

  width: 25%;

  padding-top: 5px;

  font-size: 66px;

  color: #fff;

  line-height: 100px;

  text-align: right;

  opacity: 0.3;

}

.form-bottom {

  padding: 25px 25px 30px 25px;

  background: #444;

  background: rgba(0, 0, 0, 0.3);

  -moz-border-radius: 0 0 4px 4px;

  -webkit-border-radius: 0 0 4px 4px;

  border-radius: 0 0 4px 4px;

  text-align: left;

}

.form-bottom form textarea {

  height: 100px;

}

.form-bottom form button.btn {

  width: 100%;

}

.form-bottom form .input-error {

  border-color: #de615e;

}

.social-login {

  margin-top: 35px;

}

.social-login h3 {

  color: #fff;

}

.social-login-buttons {

  margin-top: 25px;

}

/***** Media queries *****/

@media (min-width: 992px) and (max-width: 1199px) {}@media (min-width: 768px) and (max-width: 991px) {}@media (max-width: 767px) {

  .inner-bg {

    padding:60px 0 110px 0;

  }

}

@media (max-width: 415px) {

  h1,

  h2 {

    font-size: 32px;

  }

}

【问题讨论】:

    标签: twitter-bootstrap button drop-down-menu alignment


    【解决方案1】:

    我已经运行了你的代码,它看起来像这样:enter image description here

    所以您的代码是正确的,也许您在 css pass 中做了一些更改。 使用操作按钮附近的检查元素检查它,看看你在样式部分给出了多少宽度

    【讨论】:

    • 我的 css 使用“垂直对齐:中间”,我希望将其用于文本输入,但我怎样才能为按钮设置例外,以便它们水平对齐?
    • 检查你的css文件还是有样式表?
    • 样式表已发布
    • 通过检查有助于调试代码的元素并了解如何在任何模板中进行更改,自己动手做。
    【解决方案2】:

    试试这样的:

     <div class='btn-toolbar'>
        <div class='btn-group'>
            <button class="btn-danger signin">Sign In</button>
            <button class="btn-success signup">Sign Up</button>
        </div>
    </div>
    

    【讨论】:

    • 我尝试添加'btn-toolbar',没有效果。不过谢谢
    • 您是否在使用其他影响它的 css 文件?
    • 我想我的问题是我不知道哪个 CSS 元素阻碍了我的 btn-group .....
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-05-23
    • 1970-01-01
    • 1970-01-01
    • 2020-04-21
    • 1970-01-01
    • 1970-01-01
    • 2015-11-13
    相关资源
    最近更新 更多