简体   繁体   English

如何在 Twitter Bootstrap 中扩展容器的宽度

[英]How to extend width of the container in Twitter Bootstrap

I'm using the .container class in my navbar, body, and footer.我在导航栏、正文和页脚中使用了.container类。

So all three align well on the left.因此,所有三个都在左侧对齐。 However, I would like to increase the width of the container class.但是,我想增加container类的宽度。

By default the width is coming at 1170:默认情况下,宽度为 1170:

media="screen, projection"
bundle-bundle_bootstrap_head.css:6139@media (min-width: 1200px)
.container, .navbar-static-top .container, .navbar-fixed-top .container, .navbar-fixed-bottom .container {
width: 1170px;
}

However, I would like to extend the width to 1300. So I added the following in my main.css但是,我想将宽度扩展到 1300。所以我在main.css添加了以下内容

.container {
    width: 1200px;
}

But this doesn't seem to work.但这似乎不起作用。 When I reload the page and inspect the CSS, the 1200 is crossed out and 1170 is still active.当我重新加载页面并检查 CSS 时,1200 被划掉,而 1170 仍处于活动状态。

Question问题

How can I extend the default width of the container class in bootstrap?如何在引导程序中扩展container类的默认宽度?

It is probably because you are loading or main.css ( bootstrap.css ), and making your changes there.这可能是因为您正在加载或main.css ( bootstrap.css ),并在那里进行更改。 Then you are probably calling bootstrap-responsive.css after that and it is overwriting your changes.然后您可能在此之后调用bootstrap-responsive.css并且它会覆盖您的更改。

The 1170px .container width comes from the bootstrap-responsive.css file. 1170px .container宽度来自bootstrap-responsive.css文件。 It is the width assigned by default to Large Display screens (1200px and wider).它是默认分配给大显示屏(1200 像素及更宽)的宽度。 That is why I am assuming you are calling bootstrap-responsive.css after your main.css file.这就是为什么我假设您在main.css文件之后调用bootstrap-responsive.css

Using !important is an anti-pattern (a bad practice) in this regard.在这方面,使用!important是一种反模式(一种不好的做法)。 Especially on something as generic as your .container .尤其是像你的.container这样通用的.container This will lead to specificity issues in the future.这将导致未来的特异性问题。 I encourage you to actually fix and understand the problem, instead of "hacking it".我鼓励你真正解决和理解问题,而不是“破解它”。

Try this试试这个

!important can be used in cascading style sheets to give priority to parameters !important 可以在层叠样式表中使用,优先考虑参数

.container {
   width: 1200px !important;
 }

Check this for more information.检查这个以获取更多信息。

For this case !important can be used as work around, but using this property is considered as a bad practise and is not recommended by CSS experts.对于这种情况, !important 可以用作解决方法,但使用此属性被认为是一种不好的做法,CSS 专家不建议这样做。

I know this is an old thread, however I was recently searching on how to expand the container width on the newest version of bootstrap (3.0) and thought this may help others.我知道这是一个旧线程,但是我最近正在搜索如何在最新版本的引导程序(3.0)上扩展容器宽度,并认为这可能对其他人有所帮助。

Asides from setting a width for the container you must also set a max-width property to your css.除了为容器设置宽度外,您还必须为 css 设置 max-width 属性。

container 
{
  width:1200px;
  max-width:1200px;
}

As others have noted above, make sure to load your custom css after the bootstrap.css file so the settings are re declared.正如上面其他人所指出的,请确保在 bootstrap.css 文件之后加载您的自定义 css,以便重新声明设置。

In case, you're using bootstrap scss.如果您使用的是 bootstrap scss。

file: _variables.scss文件: _variables.scss

add breakpoint (here xxl: 1440px) for your bigger container width.为更大的容器宽度添加断点(此处为 xxl:1440px)。

$grid-breakpoints: (
  xs: 0,
  sm: 576px,
  md: 768px,
  lg: 992px,
  xl: 1200px,
  xxl: 1440px
) !default;

create bigger container by just adding xxl: 1200px只需添加 xxl: 1200px 即可创建更大的容器

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

Bootstrap mixins will create extra breakpoint media query for 1200px wide container. Bootstrap mixins 将为 1200px 宽的容器创建额外的断点媒体查询。

For more on changing bootstrap variable please go to Theming Bootstrap有关更改引导程序变量的更多信息,请转到主题引导程序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM