Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use "Variable width content" grid in Bootstrap 3

I'm currently using Bootstrap 3.3.7 and because my site is huge it isn't easy to migrate to v4. Nevertheless I'd like to use the new Auto-Layout-columns (Variable width content) feature (see screenshot below).

Has anybody an idea for a workaround?

bootstrap v4 doc screenshot

<div class="container-fluid">
    <div class="row">
      <div class="col-xs-6 col-xs-push-3 col-md-3">Fixed 250px</div>
      <div class="col-xs-6 col-xs-pull-3 col-md-3">Auto</div>
      <div class="col-xs-6 col-md-3">Auto</div>
      <div class="col-xs-6 col-md-3">Auto</div>
    </div>   
</div>
like image 559
mobis Avatar asked May 28 '18 12:05

mobis


People also ask

How do I change the width of a grid in Bootstrap?

The Bootstrap grid allows 12 columns with 30 px wide gutters by default, but these numbers can be adjusted. Just check the Grid System block on the Customize page. The @grid-columns field allows to set a different number of columns, and the @grid-gutter-width field lets you change the gutter width.

What are the classes grid system in Bootstrap 3?

The Bootstrap 3 grid system has four tiers of classes: xs (phones), sm (tablets), md (desktops), and lg (larger desktops). You can use nearly any combination of these classes to create more dynamic and flexible layouts.

What is offset 3 in Bootstrap?

offset-md-3 which will offset the desired column element with 3 columns to the right from its default position on medium screen sizes and above. . offset classes always shifts its content to the right.

What does Col MD 5 class means?

col-md- stands for column medium ≥ 992px. col-xs- stands for column extra small ≥ 768px. The pixel numbers are the breakpoints, so for example col-xs is targeting the element when the window is smaller than 768px(likely mobile devices)...


1 Answers

You could add the flexbox CSS that makes the auto-layout columns work in Bootstrap 4...

CSS:

.d-flex {
    display:flex;
}
.d-flex>div {
    float: none;
}
.col-auto {
    flex: 0 0 auto;
    width: auto;
    max-width: none;
}

Usage:

<div class="container">
    <div class="row d-flex">
        <div class="col-sm-3 bg-success">col-sm-3</div>
        <div class="col-auto">col-auto</div>
        <div class="col-sm-9 bg-success">col-sm-3</div>
    </div>
</div>

Demo:
https://www.codeply.com/go/cTTtpuItaM


Related: Bootstrap 3.0 - Fluid Grid that includes Fixed Column Sizes

like image 77
Zim Avatar answered Sep 24 '22 04:09

Zim