Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap 3 Fluid Container with centered content

I'm sure this might be a simple one but I haven't figured it out yet.

How do you create a full screen fluid container and have the content, including the navigation, be centered on the page, as in a non-fluid container?

I'm just trying to get the top nav/header background to stretch across the page while keeping the content at a fixed width.

like image 452
George Avatar asked Jan 10 '15 04:01

George


People also ask

How do I center content in Bootstrap 3?

There can be two ways: By adding text-align: center; in our CSS code for the tds. By adding the “ text-center” class of Bootstrap 3 to a td element also works out of the box.

How do I center a container content in Bootstrap?

Just add the class . text-center to the parent element of the text to center content horizontally.

How do I center the contents of a container?

Make the container relatively positioned, which declares it to be a container for absolutely positioned elements. Make the element itself absolutely positioned. Place it halfway down the container with 'top: 50%'. (Note that 50%' here means 50% of the height of the container.)

Is it possible to center a column in Bootstrap?

The first approach uses bootstrap offset class. The key is to set an offset equal to half of the remaining size of the row. So for example, a column of size 2 would be centered by adding an offset of 5, that's (12-2)/2.


2 Answers

You can surround the .container with your navigation content with another <div> on which you add the background styling. See the following example:

.background {
  background-color: #f99;
}

.content {
  background-color: #9f9;
}
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet" />

<div class="background">
  <div class="container">
    <div class="row">
      <div class="col-xs-12 content">Content</div>
    </div>
  </div>
</div>
like image 135
ckuijjer Avatar answered Oct 05 '22 08:10

ckuijjer


A rough method is to use the Bootstrap grid concept. Bootstrap divides your row into 12 colums. The trick consists into the insertion of a 4-black-space block before and one after your 4-space block. Example:

<div class="container-fluid">
	<div class="row">
      
		<div class="col-sm-4"></div>
      
		<div class="col-sm-4">
			<h2>Title</h2>
			<p>Your content here</p>
		</div>
      
		<div class="col-sm-4"></div>
	</div>
</div>
like image 26
mengo Avatar answered Oct 05 '22 08:10

mengo