Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 - Set Container Width to 940px Maximum for Desktops?

I am adding a whole new section to a website using Twitter Bootstrap 3, however the container cannot go wider than 940px in total for Desktop - as it will throw out the Header and Footer {includes}.

So 940px works out at 12 x 60 = 720px for the columns and 11 x 20 = 220px for the gutters. Fair enough, but how do you input these into Bootstrap 3 as there is 'no' @ColumnWidth field/setting in the Customize section?

I have tried by setting the @container-lg-desktop and @container-desktop both to 940px - but it doesn't work.

like image 204
ubique Avatar asked Oct 17 '13 14:10

ubique


People also ask

How do I change the width of a container in Bootstrap 3?

Go to the Customize section on Bootstrap site and choose the size you prefer. You'll have to set @gridColumnWidth and @gridGutterWidth variables. For example: @gridColumnWidth = 65px and @gridGutterWidth = 20px results on a 1000px layout.

How do I resize a container in Bootstrap?

You can either use <div class="container-fixed"> or your own media query in which you can specify the custom width for various resolution. Show activity on this post. The default Bootstrap . container class has 15px padding on both left and right sides.

Which Bootstrap class will you use to provide a responsive full width container?

container-fluid class provides a full width container, spanning the entire width of the viewport.


2 Answers

There is a far easier solution (IMO) in Bootstrap 3 that does not require you to compile any custom LESS. You just have to leverage the cascade in "Cascading Style Sheets."

Set up your CSS loading like so...

<link type="text/css" rel="stylesheet" href="/css/bootstrap.css" /> <link type="text/css" rel="stylesheet" href="/css/custom.css" /> 

Where /css/custom.css is your unique style definitions. Inside that file, add the following definition...

@media (min-width: 1200px) {   .container {     width: 970px;   } } 

This will override Bootstrap's default width: 1170px setting when the viewport is 1200px or bigger.

Tested in Bootstrap 3.0.2

like image 152
Frank Koehl Avatar answered Sep 25 '22 23:09

Frank Koehl


In the first place consider the Small grid, see: http://getbootstrap.com/css/#grid-options. A max container width of 750 px will maybe to small for you (also read: Why does Bootstrap 3 force the container width to certain sizes?)

When using the Small grid use media queries to set the max-container width:

@media (min-width: 768px) { .container { max-width: 750px; } }

Second also read this question: Bootstrap 3 - 940px width grid?, possible duplicate?

12 x 60 = 720px for the columns and 11 x 20 = 220px

there will also a gutter of 20px on both sides of the grid so 220 + 720 + 40 makes 980px

there is 'no' @ColumnWidth

You colums width will be calculated dynamically based on your settings in variables.less. you could set @grid-columns and @grid-gutter-width. The width of a column will be set as a percentage via grid.less in mixins.less:

.calc-grid(@index, @class, @type) when (@type = width) {   .col-@{class}-@{index} {     width: percentage((@index / @grid-columns));   } } 

update Set @grid-gutter-width to 20px;, @container-desktop: 940px;, @container-large-desktop: @container-desktop and recompile bootstrap.

like image 40
Bass Jobsen Avatar answered Sep 21 '22 23:09

Bass Jobsen