There are many ways to do this. First, you need to make the div appear as columns for large screens, and then use media queries to change them to rows for medium / small screens.
HTML for everyone:
<div class="container"> <div class="section">1</div> <div class="section">2</div> <div class="section">3</div> </div>
1. Flexbox:
Jsfiddle
.container { display: flex; } .section { flex: 1; border: 1px solid; } @media (max-width: 768px) { .container { flex-direction: column; } }
2. Float:
Jsfiddle
.container:after { content: ""; display: table; clear: both; } .section { float: left; width: 33.3333%; border: 1px solid; box-sizing: border-box; } @media (max-width: 768px) { .section { float: none; width: auto; } }
3. Built-in unit:
Jsfiddle
.container { font-size: 0; } .section { font-size: 16px; display: inline-block; vertical-align: top; width: 33.3333%; border: 1px solid; box-sizing: border-box; } @media (max-width: 768px) { .section { display: block; width: auto; } }
4. CSS table:
Jsfiddle
.container { display: table; table-layout: fixed; width: 100%; } .section { display: table-cell; border: 1px solid; } @media (max-width: 768px) { .section { display: block; } }
5. CSS grid:
Jsfiddle
.container { display: grid; grid-template-columns: 1fr 1fr 1fr; } .section { border: 1px solid; } @media (max-width: 768px) { .container { grid-template-columns: none; } }
source share