I need to build a responsive layout that goes from a 3 by 2 layout on desktop to a 2 by 3 on mobile.
Here is a basic example of my HTML layout
<section class="itineraries-hub__categories">
<div class="row">
<div class="small-6 x-large-4 columns">
...
</div>
<div class="small-6 x-large-4 columns">
...
</div>
<div class="small-6 x-large-4 columns">
...
</div>
</div>
<div class="row">
<div class="small-6 x-large-4 columns">
...
</div>
<div class="small-6 x-large-4 columns">
...
</div>
<div class="small-6 x-large-4 columns">
...
</div>
</div>
</section>
Now I can imagine a lot of you are thinking, why don't I just get rid of the 2 rows and have 1 big row, this is a valid question although I need to have each column the exact same height which I am doing with display:table
and display:table-cell
. This is why I have my HTML it the layout it is.
So then I think about using Flexbox which I'm sure you are all thinking too, the issue is that I have to support IE9 which means I cannot use flexbox for desktop. I am very open to using it for mobile.
So bearing in mind that I cannot use Flexbox on desktop and that all columns must be the same height, this is where I have become stuck. Please see below for my full HTML and CSS
.row {
display: table;
width: 100%;
}
.columns {
display: table-cell;
width: 33.4%;
}
.category__link {
cursor: pointer;
display: block;
overflow: hidden;
}
.category__image-container {
position: relative;
height: 200px;
overflow: hidden;
background: url(/assets/images/resources/blank.png);
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
img {
position: absolute;
}
.category__title {
display: block;
background: #323945;
color: white;
font-weight: 400;
font-family: 'MuseoSansW01-Rounded900', sans-serif;
font-size: 16px;
line-height: 2;
padding: 18px 14px 14px 26px;
overflow: hidden;
}
.category__tag {
float: right;
display: inline-block;
padding: 6px 12px;
margin-top: -1px;
-webkit-border-radius: 2px;
-moz-border-radius: 2px;
-ms-border-radius: 2px;
border-radius: 2px;
background: black;
text-transform: uppercase;
font-weight: 400;
font-family: 'Proxima Nova W08 Reg', sans-serif;
-webkit-font-smoothing: antialiased;
font-family: 'Proxima Nova W08 Bd', sans-serif;
font-size: 13px;
}
@media only screen and (max-width: 500px) {
.row {
display: flex;
flex-wrap: wrap;
}
.columns {
display: flex;
width: 50%;
}
}
<section class="itineraries-hub__categories">
<div class="row">
<div class="small-6 x-large-4 columns">
<a class="category__link">
<div class="category__image-container">
<img src="http://d5qsyj6vaeh11.cloudfront.net/images/whats available/landscapes/article images/w1400_a_new landscape_main.jpg">
</div>
<span class="category__title">
Discover dramatic scenes
<span class="category__tag">Explore</span>
</span>
</a>
</div>
<div class="small-6 x-large-4 columns">
<a class="category__link">
<div class="category__image-container">
<img src="http://d5qsyj6vaeh11.cloudfront.net/images/whats available/landscapes/article images/w1400_a_new landscape_main.jpg">
</div>
<span class="category__title">
Discover dramatic scenes
<span class="category__tag">Explore</span>
</span>
</a>
</div>
<div class="small-6 x-large-4 columns">
<a class="category__link">
<div class="category__image-container">
<img src="http://d5qsyj6vaeh11.cloudfront.net/images/whats available/landscapes/article images/w1400_a_new landscape_main.jpg">
</div>
<span class="category__title">
Discover dramatic scenes
<span class="category__tag">Explore</span>
</span>
</a>
</div>
</div>
<div class="row">
<div class="small-6 x-large-4 columns">
<a class="category__link">
<div class="category__image-container">
<img src="http://d5qsyj6vaeh11.cloudfront.net/images/whats available/landscapes/article images/w1400_a_new landscape_main.jpg">
</div>
<span class="category__title">
Discover dramatic scenes
<span class="category__tag">Explore</span>
</span>
</a>
</div>
<div class="small-6 x-large-4 columns">
<a class="category__link">
<div class="category__image-container">
<img src="http://d5qsyj6vaeh11.cloudfront.net/images/whats available/landscapes/article images/w1400_a_new landscape_main.jpg">
</div>
<span class="category__title">
Discover dramatic scenes
<span class="category__tag">Explore</span>
</span>
</a>
</div>
<div class="small-6 x-large-4 columns">
<a class="category__link">
<div class="category__image-container">
<img src="http://d5qsyj6vaeh11.cloudfront.net/images/whats available/landscapes/article images/w1400_a_new landscape_main.jpg">
</div>
<span class="category__title">
Discover dramatic scenes
<span class="category__tag">Explore</span>
</span>
</a>
</div>
</div>
</section>
I also have a JSFiddle https://jsfiddle.net/gd2xnfb3/1/
If anyone can help me solve this problem, remembering my requirements that would be great.