I’m writing a responsive wordpress site. I’m using the bones theme template. The grid system included worked pretty well on most of the site, but I found I needed differing number of columns on different screen sizes for a particular page.
To do this, I used a bit of scss that looks like this:
(base media query)
section{
display:table;
float:left;
margin-left:0;
width:100%;
}
(media query for 768 px and above)
section{
height:150px;
width:48.618784527%;
&:nth-child(3n+1), &:nth-child(2n){
margin-left:2.76243%;
}
&:nth-child(2n+1){
margin-left:0;
}
text-align:right;
}
(media query for 1030px and above)
.pracareas{
section{
width:31.491712705%;
&:nth-child(2n+1){
margin-left:2.76243%;
}
&:nth-child(3n+1){
margin-left:0;
}
}
}
And HTML like this
<div class="pracareas">
<section>... content</section>
<section>... content</section>
<section>... content</section>
<section>... content</section>
</div>
This works great on desktop browser and Android. But on safari I get something like this:
What’s really strange is that if I refresh and/or rotate the ipad to portrait or vice versa, I get this:
But if I click on a link leading to this page or visit it directly (typing into the url bar), the layout is messed up until I refresh or rotate.
I’m probably going to abandon this approach and go for fixed number of columns above mobile because this seems really messy. But I thought I’d ask since it is only not working on a single browser.
That’s because not all browsers render decimal values of width in percentages the same way.
Another approach could be to set breakpoints with media queries in order to target different devices.
Also try to round a bit those values and see if you manage to get an acceptable result.
See this: Are the decimal places in a CSS width respected?
Browsers handle percentages differently, it would not be wise to put too many decimals places straight into the layout. Browsers either round up or down, so you can try to round it up and see if you find a solution.