How to set the size of your Storefront Pro sliders so they don’t crop (whatever the device)

Storefront Pro home page sliders are by default set to ‘cover’. This means that whatever text you put over them, the text won’t fall outside of the image behind it. This is especially important when being viewed on a mobile phone. Here’s an explanation on why it’s best practice to set background images to cover.

If we don’t set background images to cover then this will happen. The image isn’t cropped anymore, but it the height become so small (so it fits the width of the screen) that the text no longer fits. So the text drops below the image. This is bad.

Background image not set to cover (see how the text and button no longer fit within the image but drop below it)

How to set the size of your Storefront Pro sliders so they don't crop (whatever the device) 1

So to solve this we set the background image to ‘cover’. This means that the text always fits within the image, no matter what size. This is what is actually happening.

Background image set to cover

background image covering

But this also has the result that the background image will appear cropped on some devices and screen resolutions.

However there may be times when you don’t want your background image to crop. It may be that you are just using an image, or you have designed the slider with text in the graphic.

And we can use a little bit of CSS magic to fix the ratio of your slider images.

We need to do a little simple maths first, but don’t worry it’s very simple πŸ™‚

In my example below we’ll assume my slider image is 500px height, and 1500 width.

So we divide 500 / 1500 to get the ratio = .33

This sets it so that your slider images on your home page have a height that is equal to 33% of the viewport width (vw) which is also the slider width.

And here’s the resultant code (click here to get code)

Put this code in the wordpress customizer (css section)

how to add css to wordpress

Just replace 33 below with your ratio

.home #page > nav.secondary-navigation ~ .header-hero,
.home #page .header-hero .storefront-pro-flexslider .slides li .slide-img {
    min-height: 33vw !important;
}

Comments

4 responses to “How to set the size of your Storefront Pro sliders so they don’t crop (whatever the device)”

  1. Thank you so much, that was so easy πŸ™‚

  2. Perfect! Thank you so very much

  3. Google Search console provides an usability error without adjusting the image:
    Mobile Usability > Content wider than screen. Perhaps you could give a rethink to the display on mobile. It would be great if the whole image could have a hyperlink as well, doing away with the need for a button.

  4. Hi There,
    How can this be edited and used to set a different hero image on mobile devices?

Leave a Reply

Your email address will not be published. Required fields are marked *