Seif
Seif

Reputation: 749

How to stack divs on top of each other when screen gets smaller? bootstrap

I have three divs side to side, I want them to stack on top of each other when screen gets smaller. instead, the divs resize making content look bad.

I followed the w3schools tutorial (bootstrap_grid_stacked_to_horizontal) to make them stack by putting them inside a container div and a row div in addition to adding the class col-lg-4 but they still resize.

This is relevant HTML and CSS:

.how-it-works-container{
    	padding: 50px;
    	background-color: #C5B358;
    	font-family: 'Montserrat', sans-serif;
    	opacity: .8;
    	text-align: center;
    
    	width: 100%
    }
 
    .how-it-works-box{
    	padding: 30px;
    	background-color: #D6C362;
    	margin: 20px 5px;
    	
    	width: calc(30%);
    	overflow-wrap: break-word;
    	color: white;
    	display: inline-block;
    	box-shadow: 0 4px 8px 0 rgba(255, 255, 255, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
    }
<!-- How It Works section -->
<div class="how-it-works-container container">

    <h2>How It Works</h2>

  <div class="row">

      <div class="how-it-works-box col-lg-4"> 
        <img src=" {% static "images/meetlocals3.svg" %} "> 
        <h3>Meet Local People</h3>
        <p>Meet like-minded locals who could show you around their city.</p>
      </div>

      <div class="how-it-works-box col-lg-4">
        <img src=" {% static "images/showpeople.svg" %} ">
        <h3>Show Visitors Around</h3>
        <p>Show visitors around and meet interesting international visitors.</p>
      </div>

      <div class="how-it-works-box col-lg-4">
        <img src=" {% static "images/makefriends.svg" %} ">
        <h3>Make New Friends!</h3>
        <p>Walking around is a fun bonding activity to make new friends!</p>
      </div>

    </div>
</div>

Upvotes: 2

Views: 4121

Answers (2)

Waleed Arshad
Waleed Arshad

Reputation: 273

As you know bootstrap have 12 Columns so you need to add col-xs-12 along with col-lg-4 then for extra small screen every div will take all 12-columns.

<div class="col-lg-4 col-xs-12">
    <div class="how-it-works-box">
        <img src="">
        <h3>Meet Local People</h3>
        <p>Meet like-minded locals who could show you around their city.</p>
    </div>
</div>
<div class="col-lg-4 col-xs-12">
    <div class="how-it-works-box">
        <img src="">
        <h3>Show Visitors Around</h3>
        <p>Show visitors around and meet interesting international visitors.</p>
    </div>
</div>
<div class="col-lg-4 col-xs-12">
    <div class="how-it-works-box">
        <img src="">
        <h3>Make New Friends!</h3>
        <p>Walking around is a fun bonding activity to make new friends!</p>
    </div>
</div>

and it is good to add tags for all sizes. col-md- and also for col-sm- .

Upvotes: 0

Carol Skelly
Carol Skelly

Reputation: 362520

The CSS is overriding the Bootstrap grid. Put the boxes inside the Bootstrap grid columns which will auto stack on xs screens..

http://www.codeply.com/go/gTkC50Paql

.how-it-works-container{
    padding: 50px;
    background-color: #C5B358;
    font-family: 'Montserrat', sans-serif;
    opacity: .8;
    text-align: center;
}

.how-it-works-box{
    width: 100%;
    padding: 30px;
    background-color: #D6C362;
    margin: 20px 5px;
    overflow-wrap: break-word;
    color: white;
    display: inline-block;
    box-shadow: 0 4px 8px 0 rgba(255, 255, 255, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
}

<div class="how-it-works-container container-fluid">
    <h2>How It Works</h2>
    <div class="row">
        <div class="col-lg-4">
            <div class="how-it-works-box">
                <img src="">
                <h3>Meet Local People</h3>
                <p>Meet like-minded locals who could show you around their city.</p>
            </div>
        </div>
        <div class="col-lg-4">
            <div class="how-it-works-box">
                <img src="">
                <h3>Show Visitors Around</h3>
                <p>Show visitors around and meet interesting international visitors.</p>
            </div>
        </div>
        <div class="col-lg-4">
            <div class="how-it-works-box">
                <img src="">
                <h3>Make New Friends!</h3>
                <p>Walking around is a fun bonding activity to make new friends!</p>
            </div>
        </div>
    </div>
</div>

Upvotes: 2

Related Questions