html - Jumbotron 错误边距中的 Bootstrap 警报

标签 html css twitter-bootstrap alert

我正在创建我的网站的一部分,其中包括一个 Jumbotron 和一个可折叠的警报消息,它们都来自 Bootstrap 框架。我对警告框的边距有疑问。我为 Jumbotron 使用标准 CSS 并调整了填充,但这不会影响我的问题。

这是未经修改的样子:enter image description here

我希望警告框与选择框对齐。我尝试用这个覆盖警报类的属性:

.alert-custom-style {
    margin-left: 15px;
    margin-right: 15px;
    width: 100%;
}

结果在这里:enter image description here

这对左侧确实有效,但不知何故没有考虑 margin-right 属性。我通过将 margin-left 放回 0px 来测试它,但它看起来就像第一张图片。我真的很想知道为什么左边距属性有效,而不是右边距属性。非常感谢任何建议或帮助。

这是 HTML 代码:

        <div class="jumbotron jumbotron-custom">
            <div class="row">
                <div class="col-lg-5 col-md-5 col-sm-12 col-xs-12 top-buffer">
                    <!-- Dropdown List for the first country -->
                    <select id="country1" name="Country Selection 1" class="selectpicker" data-width="100%" data-style="btn-default" data-live-search="true" title="Choose..."></select>
                </div>

                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12 top-buffer">
                    <!-- Compare Button -->
                    <button id="btnSubmit" type="Submit" class="btn btn-success btn-block">Compare</button>
                </div>

                <div class="col-lg-5 col-md-5 col-sm-12 col-xs-12 top-buffer">
                    <!-- Dropdown List for the second country -->
                    <select id="country2" name="Country Selection 2" class="selectpicker" data-width="100%" data-style="btn-default" data-live-search="true" title="Choose..."></select>
                </div>

                <!-- JavaScript file to handle the data management -->
                <script src="js/compare.js"></script>
                <!-- JavaScript file to handle the selection lists -->
                <script src="js/lists.js"></script>
            </div>

            <div class="row top-buffer">
                <div id="alert" class="collapse alert alert-custom-style col-lg-12 col-md-12 col-sm-12 col-xs-12" role="alert"> <!-- Collapsed by default -->
                    <strong>Warning: </strong><span id="alert-span">Please select at least two different countries</span>
                </div>
            </div>
        </div>

最佳答案

对于包含 top-buffer 类警报的行,尝试添加:

margin-left: 15px;
margin-right: 15px;

我没有你所有的 css,但这里有一个粗略的版本,我认为它近似于你想要的。

使用代码段底部的“整页”按钮以更宽的 View 查看结果。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />

<div class="container">
    <div class="jumbotron">
      <div class="col-lg-5 col-md-5 col-sm-12 col-xs-12 top-buffer">
        <!-- Dropdown List for the first country -->
        <select id="country1" name="Country Selection 1" class="selectpicker" style="width:100%;" data-width="100%" data-style="btn-default" data-live-search="true" title="Choose...">
        </select>
      </div>
      <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12 top-buffer">
        <!-- Compare Button -->
        <button id="btnSubmit" type="Submit" class="btn btn-success btn-block" style="width:100%;">
          Compare
        </button>
      </div>
      <div class="col-lg-5 col-md-5 col-sm-12 col-xs-12 top-buffer">
        <!-- Dropdown List for the second country -->
        <select id="country2" name="Country Selection 2" class="selectpicker" style="width:100%;" data-width="100%" data-style="btn-default" data-live-search="true" title="Choose...">
        </select>
      </div>
      <div class="row top-buffer" style="margin-left: 15px; margin-right: 15px;">
      <div id="alert" class="collapse in alert alert-custom-style col-lg-12 col-md-12 col-sm-12 col-xs-12" role="alert" style="background-color: red;"> <!-- Collapsed by default -->
        <strong>Warning: </strong><span id="alert-span">Please select at least two different countries</span>
      </div>
    </div>
  </div>
</div>

关于html - Jumbotron 错误边距中的 Bootstrap 警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43123602/

相关文章:

javascript - jQuery 复杂 Accordion

jquery - WordPress 类别菜单 jQuery/CSS 悬停

javascript - 用户选择从今天开始 10 年的日期 jquery datepicker

html - 背景渐变颜色和背景图像

html - Bootstrap 3 : Alignment of Close Icon

jquery - BootStrap 3.X Radio ButtonGroup - 获取当前选中按钮的 OnClick 触发方法

javascript - 数组更新后 Ng-Repeat 不更新

php - 如何指定多个样式表

twitter-bootstrap - 调整高度以匹配内容的 DIV

html - 如何居中对齐两个内容不同的div?