Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a fixed width column with a container-fluid?

I am trying have a side column on the left with fixed width, and then, on the right a normal Bootstrap container-fluid.

Even if the sidebar is not inside the Bootstrap structure, it is OK. I mean it hasn't to be with col-xx-xx class.

Whatever I do the main problem is that I don't manage to make the fluid container stays beside the sidebar.

The point is also that if I display to none the sidebar, the fluid container has to use the full width of the page.

like image 957
somtam Avatar asked Mar 17 '16 12:03

somtam


People also ask

What is the width of container-fluid?

container-fluid , which is width: 100% at all breakpoints. . container-{breakpoint} , which is width: 100% until the specified breakpoint.

How do I create a full width container in Bootstrap?

Choose from a responsive, fixed-width container (meaning its max-width changes at each breakpoint) or fluid-width (meaning it's 100% wide all the time). container-fluid class can be used to get full width container. container-fluid class provides a full-width container which spans the entire width of the viewport.

Which class provides a responsive fixed width container?

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

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

A fixed-fluid layout is possible in Bootstrap 3, but now that Bootstrap 4 is flexbox this layout is much easier. You just need to enable flexbox, and make a few simple adjustments to set the width of your fixed side column flex: 0 0 300px;, and then flex: 1; on your main column to fill remaining width...

Bootstrap 4 Alpha 2 http://codeply.com/go/eAYKvDkiGw

Here's a simpler update for the latest Bootstrap 4 which is flexbox by default:

Bootstrap 4 Alpha 6 or Beta http://codeply.com/go/V9UQrvLWwz

 @media (min-width: 576px) {
     .sidebar {
          max-width: 280px;
     }
 }

<div class="container-fluid">
    <div class="row flex-nowrap">
        <div class="col-md-4 col-12 sidebar">

        </div>
        <div class="col-md col-12 main">
            <h2>Main (fluid width...)</h2>
        </div>
    </div>
</div>

Also see: How to build a 2 Column (Fixed - Fluid) Layout with Twitter Bootstrap?

Update 2018 Bootstrap 4.0.0 example

like image 136
Zim Avatar answered Oct 04 '22 04:10

Zim


Try including your container-fluid in a div with margin-left: 200px (where 200px is your sidebar's width).

Then position your sidebar with position: absolute for instance

like image 42
kartsims Avatar answered Oct 04 '22 04:10

kartsims