Search code examples
htmlcssmaterialize

How to make a 7 column grid in Materialize CSS?


Im using Materialize CSS and want to make a grid with 7 columns. It's easy to do 2, 3, 4, 6, etc, but what about something 12 isn't divisible by?

I tried following this answer to build one for 7: How to set five column in row with Materialize Design?

How do I adjust for 7 columns? Here is what I have so far:

  <div class="row-cover"><div class="row-wrap"><div class="row">
    <div class="col s6 m3 l2 ">1</div>
    <div class="col s6 m3 l2">2</div>
    <div class="col s6 m3 l2">3</div>
    <div class="col s6 m3 l2">4</div>
    <div class="col s6 m3 l2">5</div>
    <div class="col s6 m3 l2">6</div>
    <div class="col s6 m3 l2 ">7</div>
 </div></div></div>

CSS

.row div {
  height: 20px;
  background-color: aquamarine;
}
.row-cover { overflow: hidden; }
.row-wrap { margin: 0 -8.33333%; }

Particularly for the large screen, small and medium work as intended. But I want large screen to have them all on one row, not like this, how the above code looks:

enter image description here

Thank you!!


Solution

  • Try this HTML and CSS

    HTML:

    <div class="row-cover">
        <div class="row-wrap">
            <div class="row centered">
                <div class="teal center col s1 offset-s2">1</div>
                <div class="blue center col s1">2</div>
                <div class="red center col s1">3</div>
                <div class="orange center col s1">4</div>
                <div class="yellow center col s1">5</div>
                <div class="green center col s1">6</div>
                <div class="brown center col s1">7</div>
           </div>
        </div>
    </div>
    

    CSS:

    .row-cover { overflow: hidden; }
    .row-wrap { margin: 0 -8.33333%; }
     @media only screen and (max-width: 767px) {
        .row-wrap { margin: 0; }
     }
     .centered{
         margin-left: 5%
     }
    

    You can change the value of max-width as per your requirement.

    Codepen Demo

    How to set five column in row with Materialize Design?