Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set width to the container div while creating a bootstrap responsive layout?

I am trying to make a bootstrap responsive layout. Here What I am trying is to short the width of the main container div. I tried setting width inline, but the layout lost its responsive nature. When I checked the bootstrap.css, the width for the container div is given auto. I would really appreciate if anyone can reveal the logic behind this. Following is the demo code of bootstrap.

PS - I don't want to shorten the width of the navbar-fixed class, I just want to shorten the width of the container without losing the responsiveness .

HTML

<div class="navbar navbar-fixed-top">
  <div class="navbar-inner">
    <div class="container">
      <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </a>
      <a class="brand" href="#">Project name</a>
      <div class="nav-collapse">
        <ul class="nav">
          <li class="active"><a href="#">Home</a></li>
          <li><a href="#about">About</a></li>
          <li><a href="#contact">Contact</a></li>
        </ul>
      </div><!--/.nav-collapse -->
    </div>
  </div>
</div>

<div class="container" >

  <!-- Main hero unit for a primary marketing message or call to action -->
  <div class="hero-unit">
    <h1>Hello, world!</h1>
    <p>This is a template for a simple marketing or informational website. It includes a large callout called the hero unit and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
    <p><a class="btn btn-primary btn-large">Learn more &raquo;</a></p>
  </div>

  <!-- Example row of columns -->
  <div class="row">
    <div class="span4">
      <h2>Heading</h2>
       <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
      <p><a class="btn" href="#">View details &raquo;</a></p>
    </div>
    <div class="span4">
      <h2>Heading</h2>
       <p>Donec id elit non mi porta gravida at eget metus. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Etiam porta sem malesuada magna mollis euismod. Donec sed odio dui. </p>
      <p><a class="btn" href="#">View details &raquo;</a></p>
   </div>
    <div class="span4">
      <h2>Heading</h2>
      <p>Donec sed odio dui. Cras justo odio, dapibus ac facilisis in, egestas eget quam. Vestibulum id ligula porta felis euismod semper. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus.</p>
      <p><a class="btn" href="#">View details &raquo;</a></p>
    </div>
  </div>

  <hr>

  <footer>
    <p>&copy; Company 2012</p>
  </footer>

</div>

CSS

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

Screenshot

Screenshot http://img442.imageshack.us/img442/7074/testjxk.jpg

like image 366
Bala Avatar asked Jul 23 '12 08:07

Bala


People also ask

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

Default container Our default .container class is a responsive, fixed-width container, meaning its max-width changes at each breakpoint.

How would you create a 100% screen width div inside a container?

The reason why your full-width-div doesn't stretch 100% to your screen it's because of its parent "container" which occupies only about 80% of the screen. If you want to make it stretch 100% to the screen either you make the "full-width-div" position fixed or use the "container-fluid" class instead of "container".

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

Width and Height Utilities The width and height can be set for an element, by using 25%, 50%, 75%, 100%, and auto values. For instance, use w-25 (for remaining values, replace 25 with those values) for width utility and h-25 (for remaining values, replace 25 with those values) for height utility.


2 Answers

In the bootstrap-responsive.css file you will find code blocks, known as media queries, like

@media (max-width: 480px) {
  /* Your CSS here */
}

and

@media (min-width: 768px) and (max-width: 980px) {
  /* Your CSS here */
}

You can set the width of content area to the appropriate width for each screen width inside of these blocks without affecting the other blocks.

like image 84
chris vdp Avatar answered Oct 06 '22 00:10

chris vdp


try this

  .container {
    width: auto;
    margin-left: 200px;
    margin-right: 200px;
  }​
like image 32
osyan Avatar answered Oct 05 '22 22:10

osyan