Skip Navigation

[Resolved] Responsive Grids

This support ticket is created 4 years, 12 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by Christian Cox 4 years, 12 months ago.

Assisted by: Christian Cox.

Author
Posts
#1386255

Hi again Christian,

Found the post supplying the CSS we used, this from Minesh on Toolset support:
https://toolset.com/forums/topic/grid-options-for-smaller-screen-sizes/

Ok can I ask ref what you have suggested?

This code we are using: <div class="col-xs-6 col-sm-4 col-lg-3">

From this docs here: hidden link

I can see what this relates to, breakpoints:
.col-xs- .col-sm- .col-md- .col-lg-

However I don;t get what the numbers in our code relate to. I guess it's columns however on our site it's a 4 col, reducing to a 3 and 2.

Also I can't see how to hide grid items on smaller screens so 1 row only remains.

#1386271

Me again, sorry.

Ok, worked out how this works to a point.

At the bottom of this page: hidden link

NEW PLACES.
I have this code:
<div class="row new-places-row">
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">[wpv-post-body view_template="loop-item-in-n-props-new"]</div>
[wpv-item index=other]
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">[wpv-post-body view_template="loop-item-in-n-props-new"]</div>
[wpv-item index=4]
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">[wpv-post-body view_template="loop-item-in-n-props-new"]</div>
</div>
[wpv-item index=pad]
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3"></div>
[wpv-item index=pad-last]
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3"></div>
</div>

And for the better part of it, it works just as the CSS did.

However, how do I have, on smaller screens just one row?
I would like it that the row's don't wrap and only show 1 row.

Also how flexible is it?

If I wish to change the breakpoints, or say on landscape iPad we wish to have 3 columns rather than the 2 showing?

Agree with Christian, this does seem a cleaner option than using the CSS Minesh supplied in an earlier ticket.

Thanks as always. P

#1386497

However I don;t get what the numbers in our code relate to. I guess it's columns however on our site it's a 4 col, reducing to a 3 and 2.
The Bootstrap grid is based on 12 total columns, which altogether will fill up the available horizontal space. The numbers here correspond to how many of those 12 columns each element should span. Combine that with the screen size abbreviations xs, sm, md, lg etc. to dictate how many columns should be spanned at each breakpoint, respectively.

In other words col-xs-12 will span all 12 columns at very small screen sizes (12/12 or full screen width), col-xs-6 will span 6 columns at very small screen sizes (6/12 or half the screen width), col-xs-4 will span 4 columns at very small screen sizes (4/12 or one third the screen width), col-xs-3 will span 3 columns at very small screen sizes (3/12 or one fourth the screen width), and so on. The number reflects the number of columns out of 12 will be filled by the element.

Also I can't see how to hide grid items on smaller screens so 1 row only remains.
I would like it that the row's don't wrap and only show 1 row.
The number of rows isn't responsive like this in Bootstrap, only the number of columns per row. If you want to hide rows, you have two options.
1. Write custom CSS, HTML or JavaScript. I can show you how to hide all but the first element in each row at very small sizes by adding the hidden-xs class to all items except the first index in the loop:

[wpv-item index=1]
<div class="row new-places-row">
<div class="col-xs-12 col-sm-6 col-md-4 col-lg-3">[wpv-post-body view_template="loop-item-in-n-props-new"]</div>
[wpv-item index=other]
<div class="hidden-xs col-sm-6 col-md-4 col-lg-3">[wpv-post-body view_template="loop-item-in-n-props-new"]</div>
[wpv-item index=4]
<div class="hidden-xs col-sm-6 col-md-4 col-lg-3">[wpv-post-body view_template="loop-item-in-n-props-new"]</div>
</div>
[wpv-item index=pad]
<div class="hidden-xs col-sm-6 col-md-4 col-lg-3"></div>
[wpv-item index=pad-last]
<div class="hidden-xs col-sm-6 col-md-4 col-lg-3"></div>
</div>

However, that does not help you hide all the rows after the first row. That kind of depends on the rest of the page. If I could see it in the browser I might be able to suggest something.

2. Create a separate View that includes a maximum of one result, and include both Views on the page. Use Bootstrap's responsive utility classes to only show one View at a time. For example:

<div class="visible-xs-block">
   ...place the View with max one result here for small screens...
</div>

<div class="hidden-xs">
  ...place the View that allows many rows here for other screens...
</div>

Responsive utility class documentation: https://getbootstrap.com/docs/3.3/css/#responsive-utilities

Also how flexible is it? If I wish to change the breakpoints, or say on landscape iPad we wish to have 3 columns rather than the 2 showing?
The breakpoint classes are based on Bootstrap's predefined resolution breakpoints, in terms of numbers of pixels. Those resolutions are documented here:
https://getbootstrap.com/docs/3.3/css/#grid-media-queries
I suggest you do not attempt to manipulate those breakpoints unless you are an expert CSS programmer. That type of customization is not supported here in the forums.

In terms of specific devices and their sizes at different orientations, I'm not fully aware of those (there are probably multiple different resolutions for different iPad versions, for example) so I'm not sure about that. I can only tell you based on pixel dimensions which of these breakpoints will apply. Widths of 992px-1200px will use the md- class column counts. Widths of 768px-992px will use the sm- class column counts, and so on based on the definitions in the documentation link above. You can probably find the relevant iPad resolutions online to determine which breakpoints apply at different orientations.

#1386627

Morning,

Thank you for your time.

The Bootstrap docs, once read make things pretty clear. This is where it became very clear: hidden link
This alone made it easier to understand what the codes mean like these:
"col-xs-12 col-sm-6 col-md-4 col-lg-3"

I can see by experimenting what they do to different screen sizes. Works very well.

However the flexibility wouldn't be an issue if Minesh here hadn't offered 'different' advice:
https://toolset.com/forums/topic/grid-options-for-smaller-screen-sizes/

This is where I was suggested to use CSS by Minesh:


@media (min-width: 768px) and (max-width: 1024px) {
.new-places-row .col-sm-4:nth-child(n+3) {
display: none;
}
}

@media (min-width: 768px) and (max-width: 1024px) {
.new-places-row .col-sm-4 {
width: 50%;
}
}

So we have used this and tested it, it works on all screen sizes. Only, in this instance, one row only ever displays. It's far more responsive and controllable than Bootstrap alone.

Check this page at the bottom, two rows. Top all Bootstrap, the lower CSS. The CSS has a better breakpoint and more controllable: hidden link

Now I understand what you're suggesting, and finding Minesh's post can see what to do with this CSS.
I'm concerned you suggested in my other ticked using CSS is not the preferred way to going about this.

It's like I'm being offered conflicting advice from support and I have to choose, this while I'm new to using Bootstrap 'not' media quires and CSS.

#1387093

It's like I'm being offered conflicting advice from support
I don't see this code recommended in the other ticket:

@media (min-width: 768px) and (max-width: 1024px) {
.new-places-row .col-sm-4 {
width: 50%;
}
}

Again, this code modifies the Bootstrap grid class widths in a way that is unnecessary. If this was recommended by Minesh, and I can't see that it was in the ticket, I'll speak with our team about it, because this isn't the right way to implement responsive grids. That's the only code that I really have a problem with.

The other recommendation is an example showing how to use the nth-child selector to hide grid elements at a particular range of screen widths:

@media only screen and (min-width:768px) and (max-width:1199px) {
    .new-places-row .col-sm-4:nth-child(n+4) {
        display: none;
    }
}

This code example provided by Minesh was an example, and he mentioned that you may need to adjust it to suit your requirements. If you understand how the nth-child selector works, you can use it to hide the (n)th element(s) in a parent selector. So you could use this code as a guide for implementing two of the features you requested:
- How to hide all but the first element in a .new-places-row at very small screen sizes. This approach is very similar to the Bootstrap responsive utility approach I recommended, and you're welcome to try either way. This is more of a pure CSS approach, where the other method I recommended is a Bootstrap class-based approach. Which approach is better is argumentative, and largely depends on your understanding of CSS code. My approach requires less coding, since you don't have to write out the media query yourself. Minesh's approach may be more flexible, but also requires more understanding of CSS code and the potential effects of changing the code here.
- How to hide all but the first .new-places-row in the View at very small screen sizes. I can't see the View's configurations so I'm guessing that you have the wrap setting set to "4" for this View, and the new-places-row is inside the wpv-loop tags. If more than 4 results are found, this View will generate more than one new-places-row. If that is the case, the nth-child selector is how I would go about hiding all but the first new-places-row. It's a smart solution that doesn't require a second View. So I would say Minesh went above and beyond the recommendations I made by adding this code example to introduce the nth-child selector concept for you. I don't think it conflicts with my recommendations, one of which was custom code. This is an example of such custom code.

#1387225

Hi there,

Thanks for your message. Ok I do understand what you're saying and can see what you are suggesting is cleaner and more straight forward.

However Minesh in this ticket: https://toolset.com/forums/topic/grid-options-for-smaller-screen-sizes/

Offered what I see as a more flexible option. I only favor it because it's more flexible. I can change the breakpoints and adjust this to our needs which is great.

Using just Bootstrap isn't working as well as Minesh's suggestion and the only reason we may favor and stick with it.

To be fair I didn't know I had the info from Toolset support so had no ref to revisit which is why I approached support again. Now I know what Minesh was suggesting I can see what he was meaning.

I wish things to be as clean and straight forward as they can be however while I don't fully understand Toolset and Bootstrap fully, media queries are logical and completely flexible.

I may stick with this, only due to it's more flexible than Bootstrap alone.

I'm going to do a little more reading and research on this.

#1387231

Great, it sounds like you are able to make an informed judgement, given all the information on hand, about which approach works best for your needs. I'll stand by for your update.