Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make flex row responsive Bootstrap 4

Currently the page looks like this:

enter image description here

Now on resize to mobile screen flex boxes overflow the container:

enter image description here
Html:

       <div id="bars" class="d-flex flex-row text-white  text-center">
            <div class="port-item p-4 bg-primary" data-toggle="collapse" data-target="#home">
                <i class="fa fa-home d-block"></i> Home
            </div>
            <div class="port-item p-4 bg-success" data-toggle="collapse" data-target="#resume">
                 <i class="fa fa-graduation-cap d-block"></i> Resume
            </div>
            <div class="port-item p-4 bg-warning" data-toggle="collapse" data-target="#work">
                 <i class="fa fa-folder-open d-block"></i> Work
            </div>
            <div class="port-item p-4 bg-danger" data-toggle="collapse" data-target="#contact">
            <i class="fa fa-envelope d-block"></i> Contact
            </div>
            </div>

CSS, I tried with media but nothig has changed

.port-item {
width: 30%;
}

@media(min-width: 768px) {
  #bars {
    flex-direction: column;
  }
}

How can I make them fit to container or to make them to display on column

like image 602
lejhbah Avatar asked Sep 16 '17 18:09

lejhbah


People also ask

Is bootstrap flex responsive?

Quickly manage the layout, alignment, and sizing of grid columns, navigation, components, and more with a full suite of responsive flexbox utilities.

Does bootstrap 4 Use flexbox?

Flexbox. The biggest difference between Bootstrap 3 and Bootstrap 4 is that Bootstrap 4 now uses flexbox, instead of floats, to handle the layout. The Flexible Box Layout Module, makes it easier to design flexible responsive layout structure without using float or positioning.

How do you get flex to align horizontally?

Use justify-content for the alignment of items horizontally. Use align-items to align items vertically.


1 Answers

Not sure you need to use CSS to sort this as the Bootstrap classes should cover this.

Replace your flex class "d-flex flex-row" with "d-flex flex-column d-sm-flex flex-sm-row"

and your 4 items will auto stack on mobile and go side by side above that

like image 158
72GM Avatar answered Sep 22 '22 12:09

72GM