简体   繁体   English

为什么Twitter Bootstrap“固定”布局没有修复?

[英]Why is the Twitter Bootstrap “fixed” layout NOT fixed?

The Twitter Bootstrap site reads as follows: Twitter Bootstrap网站内容如下:

The default and simple 940px-wide, centered layout for just about any website or page provided by a single <div class="container"> . 对于由单个<div class="container">提供的几乎任何网站或页面,默认和简单的940px宽,居中布局。

Quote from http://twitter.github.com/bootstrap/scaffolding.html#layouts 引自http://twitter.github.com/bootstrap/scaffolding.html#layouts

That's exactly what I have in my HTML but when I inspect the element, I see this CSS apply to it: 这正是我在HTML中所拥有的,但当我检查元素时,我看到这个CSS适用于它:

.container, .navbar-fixed-top .container, .navbar-fixed-bottom .container {
    width: 1170px;
}

By the way, if I override that CSS rule by adding... 顺便说一句,如果我通过添加...来覆盖CSS规则

div.container{
  width:940px;
}

Then the elements inside the div.container are wider than the div.container itself and look out of place. 然后div.container中的元素比div.container本身更宽,看起来不合适。

So, why is the Twitter Bootstrap "fixed" layout NOT fixed? 那么,为什么Twitter Bootstrap“固定”布局不固定? and how can I make it fixed? 以及如何修复它?

Update 更新

In newer version of bootstrap, since 2.1.0 (I think) you can modify the responsive grid sizes in variables.less : source on github 在更新版本的bootstrap中,从2.1.0开始(我认为)你可以在variables.less修改响应式网格大小: 源代码在github上

So if you are compiling your CSS from Less, you can modify those variables. 因此,如果您从Less编译CSS,则可以修改这些变量。 Otherwise, the solution below is still valid. 否则,以下解决方案仍然有效。


This is because you included the responsive layout. 这是因为您包含了响应式布局。 Check the doc 检查文档

If you look at this file github responsive-1200px-min.less (2.0.4) or github responsive-1200px-min.less (2.1.0) 如果你看看这个文件github responsive-1200px-min.less(2.0.4)github responsive-1200px-min.less(2.1.0)

You can see that 你可以看到

 @gridColumnWidth: 70px; // First parameter @gridGutterWidth: 30px; // Second parameter 

Which gives 70*12 + 30*(12-1) = 1170px (12 being the @gridColumns ). 其中70*12 + 30*(12-1) = 1170px (12为@gridColumns )。

So if you want the static, non-responsive, 940px wide grid, you have to remove the bootstrap-reponsive.css file from your includes. 因此,如果您需要静态,无响应,940px宽的网格,则必须从包含中删除bootstrap-reponsive.css文件。

As for the RoR equivalent of that, any input is appreciated. 至于RoR等价物,任何输入都是值得赞赏的。

Are you sure you have an up to date version of Twitter Bootstrap ? 你确定你有Twitter Bootstrap的最新版本吗? My bootstrap.css says (line 197): 我的bootstrap.css说(第197行):

.container,
.navbar-fixed-top .container,
.navbar-fixed-bottom .container {
    width: 940px;
}

As you mention you are using twitter-bootstrap-rails the vendor/toolkit/twitter/bootstrap/variables.less states: 如你所说,你正在使用twitter-bootstrap-rails vendor/toolkit/twitter/bootstrap/variables.less状态:

// Default 940px grid
// -------------------------
@gridColumns:             12;
@gridColumnWidth:         60px;
@gridGutterWidth:         20px;
@gridRowWidth:            (@gridColumns * @gridColumnWidth) + (@gridGutterWidth * (@gridColumns - 1));

Thats the standard files right from the https://github.com/seyhunak/twitter-bootstrap-rails 这是标准文件,直接来自https://github.com/seyhunak/twitter-bootstrap-rails

You might be using some other version of it? 你可能正在使用它的其他版本?

I think your miss understanding the term fixed for bootstrap. 我想你错过理解为bootstrap固定的术语。 When Bootstrap mentions fixed they mean it doesn't re-size the width of the content based on the size of the browser, but Fluid will. Bootstrap提到固定时,它们意味着它不会根据浏览器的大小重新调整内容的宽度,但Fluid会。

So if you change the container, you should also change the default width of the row class. 因此,如果更改容器,还应更改row类的默认宽度。 ie: .row { width: 940px; } 即: .row { width: 940px; } .row { width: 940px; }

you might have to do so with other classes as well. 您可能还必须与其他课程一起这样做。 Bootstrap also provides a customization page here Bootstrap还在此处提供自定义页面

Hope that helps, 希望有所帮助,

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

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