【问题标题】:How to place buttons next to each other using css Bootstrap如何使用 css Bootstrap 将按钮彼此相邻放置
【发布时间】:2016-02-12 04:35:40
【问题描述】:

我需要在同一行中并排放置一些按钮。另外,我喜欢将带有按钮的文本输入都放在同一行。

这是我所做的

<div class="well">

        <table class="I3WorkAroundTable">
            <tr>
                <td>
                    <div class="inlinebox">

                        <button type="button" class="btn btn-primary scripter_header_button" id="MasterRequestBreak">Request Break</button>

                        <button type="button" class="btn btn-primary scripter_header_button" id="MasterReturnToCampaign">Return to Campaign</button>

                        <button type="button" class="btn btn-primary scripter_header_button" id="MasterRequestLogoff">Logout off Campaign</button>

                        <button type="button" class="btn btn-primary scripter_header_button previewCallOption" id="MasterSkip">Skip this Call</button>

                        <button type="button" class="btn btn-primary scripter_header_button previewCallOption" id="MasterPlace">Place this Call</button>

                    </div>

                </td>
                <td class="I3WorkAroundTableRight">

                    <div class="inlinebox">

                        <div class="input-group">
                            <input type="text" class="form-control" id="MasterAlternativePhoneNumber" style="width: 120px;">
                            <span class="input-group-btn">
                                <button class="btn btn-primary" type="button">Dial</button>
                            </span>
                        </div>

                    </div>

                    <div class="inlinebox">

                        <button type="button" class="btn btn-primary scripter_header_button" id="MasterTransferCall">Transfer Call</button>

                        <button type="button" class="btn btn-primary scripter_header_button " id="MasterAnsweringMachine">Answering Machine</button>

                        <button type="button" class="btn btn-primary scripter_header_button " id="MasterWrongNumber">Wrong Number</button>

                    </div>
                </td>
            </tr>
        </table>

    </div>

但是,在我添加以下代码的地方,将最后 3 个按钮移动到其他按钮的垂直中心。

        <div class="inlinebox">

            <div class="input-group">
                <input type="text" class="form-control" id="MasterAlternativePhoneNumber" style="width: 120px;">
                <span class="input-group-btn">
                    <button class="btn btn-primary" type="button">Dial</button>
                </span>
            </div>

        </div>

这是我的 CSS 代码

.I3WorkAroundTable 
{
  width: 100%;
  padding: 0;
  margin: 0;
}

.I3WorkAroundTableRight
{
  min-width: 180px;
}

.inlinebox
{
  display: inline-block;
  *display: inline;
}

这里有一些屏幕截图显示它们是如何不对齐的

更新 这就是页面在页面内部的外观,这会强制 IE8 可比性视图

【问题讨论】:

    标签: css html twitter-bootstrap button


    【解决方案1】:

    .inlinebox 包装器中包含的所有子元素都有不同的行高(一些使用相对单位指定,另一些使用绝对像素值设置)并且默认设置为vertical-align: middle。作为快速修复,请在 .inlinebox 类上指定 line-heightvertical-align 属性:

    .I3WorkAroundTable {
      width: 100%;
      padding: 0;
      margin: 0;
    }
    .I3WorkAroundTableRight {
      min-width: 180px;
    }
    .inlinebox {
      display: inline-block;
      *display: inline;
      line-height: 1;
      vertical-align: top;
    }
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
    <div class="well">
      <table class="I3WorkAroundTable">
        <tr>
          <td>
            <div class="inlinebox">
              <button type="button" class="btn btn-primary scripter_header_button" id="MasterRequestBreak">Request Break</button>
            </div>
          </td>
          <td class="I3WorkAroundTableRight">
            <div class="inlinebox">
              
              <div class="input-group" style="width: 160px">
                <input type="text" class="form-control" id="MasterAlternativePhoneNumber" >
                <span class="input-group-btn">
                    <button class="btn btn-primary" type="button">Dial</button>
                </span>
              </div>
              </div>
            
            <div class="inlinebox">
              <button type="button" class="btn btn-primary scripter_header_button" id="MasterTransferCall">Transfer Call</button>
            </div>
          </td>
        </tr>
      </table>
    </div>

    我还将&lt;input&gt; 元素上的固定宽度移动到.input-group

    为了在浏览器之间获得更好的一致性,并且由于您已经在使用 Bootstrap,您可以考虑将 Bootstrap grid 用于基于列的布局而不是使用 &lt;table&gt;,或者使用带有 float:left 的块级元素而不是尝试将所有内容与display: inline-block 水平对齐。

    【讨论】:

    • 感谢您的帮助。该站点的问题在于它在查看器中运行。查看器强制页面在 IE8 可比性视图中移动,我无法改变它。当我渲染页面网格时由于某种原因看起来不对。您的代码修复了现代浏览器中的问题,但问题仍然存在于 IE8 比较模式中。我用查看器中的屏幕截图更新了我的问题。我该如何解决这个问题?
    • 另外,我不能使用这个&lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt; 否则查看器将无法工作。
    • 有了这些附加信息和您的 IE8 屏幕截图,似乎要解决的问题不止一个,使用 Bootstrap 甚至可能不是这个项目的好选择?我会首先让.input-group 在您的IE8 查看器中正确格式化,然后担心附加内联按钮的对齐作为第二步。这些可能会有所帮助:IE display inline blockBootstrap 3 Horizontal Form / IE8 Support
    • 如果您在IE8兼容模式下访问Bootstrap 3 documentation for input groups,它们是否正常工作?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-22
    • 2015-07-27
    • 1970-01-01
    • 1970-01-01
    • 2017-09-14
    • 1970-01-01
    相关资源
    最近更新 更多