Search code examples
bulma

Bulma change column number for desktop breakpoints


I have this simple 4 column design

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Hello Bulma!</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.5/css/bulma.min.css">
<style type="text/css" >
.title, .subtitle{color: #fff!important;}
#col1{background:#088;}
#col2{background:#808;}
#col3{background:#008;}
#col4{background:#888;}
</style>
    <script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
  </head>
  <body>
  <section class="section">
    <div class="container">
      <div class="columns">
        <div id="col1" class="column">
          <h1 class="title">Hello World</h1>
          <p class="subtitle">My first website with Bulma</p>
        </div>
        <div id="col2" class="column">
          <h1 class="title">Hello World</h1>
          <p class="subtitle">My first website with bulma</p>
        </div>
        <div id="col3" class="column">
          <h1 class="title">Hello World</h1>
          <p class="subtitle">My first website with Bulma</p>
        </div>
        <div id="col4" class="column">
          <h1 class="title">Hello World</h1>
          <p class="subtitle">My first website with bulma</p>
        </div>
      </div>
    </div> <!--container-->
  </section>
  </body>
</html>

and I want it to switch to 2 columns between 768px and 1216px. I'm new to Bulma, what is the best way to do that ?

  1. create a hidden 2 column design and switch to visible with css
  2. use javascript to change the css class of this 4 column design for the specific screen size range
  3. use another possible way with bulma that I don't know coz It's my first bulma attempt

Solution

  • What you probably want is one column to be half of columns space on tablet. You can achieve it like so:

      <section class="section">
        <div class="container">
          <div class="columns is-multiline">
            <div id="col1" class="column is-3-desktop is-half-tablet">
              <h1 class="title">Hello World</h1>
              <p class="subtitle">My first website with Bulma</p>
            </div>
            <div id="col2" class="column is-3-desktop is-half-tablet">
              <h1 class="title">Hello World</h1>
              <p class="subtitle">My first website with bulma</p>
            </div>
            <div id="col3" class="column is-3-desktop is-half-tablet">
              <h1 class="title">Hello World</h1>
              <p class="subtitle">My first website with Bulma</p>
            </div>
            <div id="col4" class="column is-3-desktop is-half-tablet">
              <h1 class="title">Hello World</h1>
              <p class="subtitle">My first website with bulma</p>
            </div>
          </div>
        </div>
      </section>
    

    This way you'll have 4 columns on desktop and 2 columns on size between 769px and 1023px.

    Example fiddle.

    See more here on Bulma responsive helpers.