如何在Max width上增加Bootstrap容器的宽度?

时间:2016-07-20 11:33:42

标签: html css twitter-bootstrap containers contentsize

我在类型容器的Bootstrap div中放置了DataTable。当我在浏览器的最大宽度上运行网站时,表格的容器会添加滚动条并切断表格中的最后一列。

我确实尝试使用建议herecontainer-fluid div类型,但这会进一步减少表容器的宽度。

在检查元素时,似乎周围container body-content继承形式的布局页面是在表容器的左侧和右侧添加边距:

enter image description here

我正在考虑的一种可能的解决方案是减少最大宽度上继承的container body-content的边距,但我不确定如何通过CSS来做到这一点。

从下面的屏幕截图中可以看到删除col正在被切断,尽管表中有很多空白的边缘要扩展:

enter image description here

问题:

如何在Max width上增加Bootstrap容器的宽度?

表容器标记的要点:

<div class="container">


    <div class="form-group">
        <div class="table-responsive">
            <div class="table-responsive" id="datatable-wrapper">

                <table id="escalation" class="table table-striped table-bordered" cellspacing="0">
                    <thead>
                        <tr>
                            <th style="font-size: 12px; border-right: 1px solid #7591ac; ">ID</th>
                            <th style="font-size: 12px; border-right: 1px solid #7591ac; ">Application</th>
                            <th style="font-size: 12px; border-right: 1px solid #7591ac; ">UID</th>
                            <th style="font-size: 12px; border-right: 1px solid #7591ac; ">Type</th>
                            <th style="font-size: 12px; border-right: 1px solid #7591ac; ">Status</th>
                            <th style="font-size: 12px; border-right: 1px solid #7591ac; ">Statement</th>
                            <th style="font-size: 12px; border-right: 1px solid #7591ac; ">Created</th>
                            <th style="font-size: 12px; border-right: 1px solid #7591ac; ">Updated</th>
                            <th style="font-size: 12px; border-right: 1px solid #7591ac; ">Last Update</th>
                            <th style="font-size: 12px; border-right: 1px solid #7591ac; ">Next Update</th>
                            <th style="font-size: 12px; border-right: 1px solid #7591ac; ">Root Cause</th>
                            <th style="font-size: 12px; border-right: 1px solid #7591ac; ">Details</th>
                            <th style="font-size: 12px; border-right: 1px solid #7591ac; ">Delete</th>
                        </tr>
                    </thead>
                    <tbody>
                        @foreach (HP.ESCALATION.Web.Models.Escalation item in Model)
                        {

                            <tr>
                                <td>@item.ID</td>
                                <td>@item.Application</td>
                                <td class="td-limit">@item.EM</td>
                                <td class="td-limit">@item.Event</td>
                                <td class="td-limit">@item.status</td>
                                <td class="td-limit">@item.Statement</td>
                                <td class="td-limit">@item.Created</td>
                                <td class="td-limit">@item.Updated</td>
                                <td data-order="@item.UnixTimeStamp" class="td-limit">@item.UpdatedTime</td>
                                <td class="td-limit">@item.NextUpdate</td>
                                <td class="td-limit">@item.RootCause</td>
                                @* Add CRUD buttons to each table row --> *@
                                <td><button type="submit" style="background-color: #0CA281;" class="btn btn-success details">Details</button></td>
                                <td><button type="submit" class="btn btn-danger delete">Delete</button></td>
                            </tr>

                        }


                    </tbody>
                </table>




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

布局容器的要点:

<div class="container body-content" style="margin-top: 90px; margin-bottom: 70px;">

                @* Main Content Render *@
                <div id="content">
                    <div class="content-wrapper main-content clear-fix">

                    </div>
                    @RenderSection("featured", required: false)
                    <section class="content-wrapper main-content clear-fix">
                        @RenderBody()
                    </section>
                </div>


            </div>  

9 个答案:

答案 0 :(得分:6)

以上答案都不是好的解决方案。您可以通过创建新的_project_variables.scss并在引导前将其导入主scss文件中来轻松更改引导程序的变量。例如:

// Grid containers
//
// Define the maximum width of `.container` for different screen sizes.

$container-max-widths: (
        sm: 540px,
        md: 720px,
        lg: 960px,
        xl: 1280px
) !default;

答案 1 :(得分:5)

在这种情况下工作但仍允许容器在较小分辨率上调整大小的解决方案是使用@media定位CSS:

@media only screen and (min-width : 1200px) {

    .container { width: 1500px; } 

}

答案 2 :(得分:2)

您可以通过将容器的css添加为

来覆盖引导程序css
.container { width: 1400px; } 

make sure this css file is added after the bootstrap css

答案 3 :(得分:1)

使用css增加容器的宽度目标容器:

.container{
   max-width: 1400px; //Or whatever value you need
}

您可以使用媒体查询来指定此样式也适用的断点

答案 4 :(得分:1)

在Bootstrap 4中使用:

@media only screen and (min-width : 1200px) {
    .container { max-width: 1500px; }
}

答案 5 :(得分:0)

  

一种可能的解决方案我在想是否要减少边际   在最大宽度上继承了容器body-content,但我不知道如何   通过CSS做到这一点。

尝试将以下内容添加到CSS中

.container.body-content{
  margin-left:0;
  margin-right:0;
  padding-left:0;
  padding-right:0;
}  

没有一个工作演示来测试它,很难判断这是否足够好,或者是否需要改进。

祝你好运!

答案 6 :(得分:0)

据此:“ https://developer.mozilla.org/en-US/docs/Web/CSS/max-width”-“ none”可用,在Bootstrap中,我认为效果更好:

@media only screen and (min-width : 1200px) {
    .container { max-width: none; }
}

答案 7 :(得分:0)

我还需要我的屏幕也可以使用超大屏幕,所以我在下面添加了。

/* large devices */
@media (min-width: 1200px) {
  .container {
     max-width: 1200px;
   }
}
/* extra large devices */
@media screen and (min-width: 1800px) {
  .container {
    max-width: 1800px;
  }
}

答案 8 :(得分:0)

对于使用Sass家伙的Bootstrap 4

@include media-breakpoint-up(xl) {
    .container {
        max-width: 1440px;
    }
}

享受!

相关问题