storefront icon indicating copy to clipboard operation
storefront copied to clipboard

edit Storefront css media queries breakpoints from the child theme

Open louisdoe opened this issue 7 years ago • 27 comments
trafficstars

Hi,

I use Storefront as a base theme to develop child themes. It'd be really useful to be able to change the css breakpoint for small screen from the functions.php instead of having to recompile the SASS. For example, the css breakpoint is hardcoded as min-width: 768px but if you need to display the mobile layout on an ipad for instance, you have to move this value.

Something like this Woocommerce hook would be nice:

add_filter('woocommerce_style_smallscreen_breakpoint','woo_custom_breakpoint'); function woo_custom_breakpoint($px) { $px = '769px'; return $px; }

Thanks for your help

louisdoe avatar Nov 05 '18 15:11 louisdoe

In the referenced topic, @jameskoster says:

768 was the breakpoint we chose so as to serve the 'mobile' layout to iPad portrait. 4 product columns displayed on screens that narrow looks pretty bad

But as far as I can tell the iPad is not being served the mobile layout in portrait mode. Am I missing something?

If there is a way to get the mobile layout to show for 768px screen width that would be great. It does indeed look pretty bad, and the desktop dropdown menus are not touch-friendly since the parent menus are links themselves.

govinda-lm avatar Nov 11 '18 01:11 govinda-lm

Exactly, by default with Storefront, the mobile layout is not served for iPad. But this is what I am looking for. And it would be great to have a php hook for this, instead of having to recompile the sass into CSS and reinstall Storefront.

louisdoe avatar Nov 12 '18 11:11 louisdoe

Just to clarify, this problem is wider (pun intended) than just Storefront. CSS core has no clear way to distinguish between an iPad Pro or a small computer screen, even though the haptics are very different on those.

That of course doesn't take away from your comment that it'd be great to override the breakpoints in an easier fashion, but I'm wondering why you'd want to do that in the first place?

These breakpoints have been tested and you can still see a full site nicely without using mobile there:

http://cld.wthms.co/ztcBtP Link to image here: http://cld.wthms.co/ztcBtP.

But let's see what the developers say about that.

jobthomas avatar Nov 12 '18 11:11 jobthomas

Hi thanks for your comment. The reason is just that my client want to display the mobile layout on iPad. Because several other big brands are doing it too.

louisdoe avatar Nov 12 '18 13:11 louisdoe

Grrr I am struggling with this, everytime there's an update of Storefront, I have to recompile it :+1:

change the breakpoint value in _variable.scss npm intall grunt check with grep that this went to css correctly reinstall Storefront

Any chance you guys can make it possible to change the breackpoints from the a child theme ?

louisdoe avatar Dec 20 '18 14:12 louisdoe

@louisdoe for now I'd suggest creating a child theme with your custom CSS. This way it won't get replaced when you update the parent theme (Storefront).

I'm labelling this an enhancement, but at the moment making this change is not a priority.

tiagonoronha avatar Dec 20 '18 17:12 tiagonoronha

@tiagonoronha this is what I am doing ! I think you don't understand: I already use a child theme, but it doesn't change the fact that the media queries breakpoints are "hardcoded in sass" in storefront theme (the parent them)! do you understand? So the breakpoints of the parent them should be editable in from the child theme...which is not the case, and other people are having the same issue, so this should BE A PRIORITY !

louisdoe avatar Dec 21 '18 10:12 louisdoe

I agree with @louisdoe. We really need a better way of changing the breakpoints.

clb92 avatar Apr 03 '19 09:04 clb92

Totally agree! Please make this a priority.

soulstyle avatar May 03 '19 11:05 soulstyle

Still nothing?

boutzamat avatar Apr 27 '20 16:04 boutzamat

Come on make this a priority ! Basic feature really !

louisdoe avatar Apr 27 '20 20:04 louisdoe

It would be so cool to have the possibility to change the breakpoints easely. Please ! :)

locougil avatar May 19 '20 15:05 locougil

This is a pretty basic feature most theme have by default. A way to modify the breakpoints from either the admin UI or using hooks. Having to modify the parent themes defeats the purpose of having a child theme and it's not the "Wordpress way".

zietbukuel avatar Jun 04 '20 10:06 zietbukuel

this was requested today at WCEU Woo virtual booth

rcstr avatar Jun 05 '20 17:06 rcstr

Might be useful to collate some examples of themes that are considered to be doing this well to help us decide on effort required and approach.

findingsimple avatar Jun 07 '20 22:06 findingsimple

I did a little research to get a better idea of how this works in Storefront and what options we might have.

Please feel free to comment linking to themes that offer this kind of feature, or if you have ideas for how we could implement in Storefront.

Do other themes offer this?

I found a couple of paid themes that offer customizable breakpoints as a feature:

I also looked at Twenty Twenty, and it doesn't seem to have support for customising breakpoints.

How does it work in other themes?

I think how this works in some themes is that they generate the css on the fly in PHP. The breakpoint values are substituted either via a PHP hook or customizer option (or some other custom UI).

What does Storefront currently provide?

Storefront uses Susy framework for layout, and for generating the css media queries for the responsive breakpoints. The values for the actual breakpoints are defined in scss variables.

Some of Storefront's css is generated by a SASS build process, in particular the css for layout and responsive modes. So this can't be changed easily - the breakpoints are locked in a build time.

This is essentially what this bug report is about - sites want to use the responsive styles provided by Storefront, but at different breakpoints. Understandably, they want to do this without forking Storefront, so they can keep their custom breakpoints and still update Storefront to get bug fixes. I don't think this is currently easy or supported.

Note that some of Storefront's css is generated by PHP. This is an older approach – building from SASS has many advantages and features that makes the stylesheets easier to develop and maintain.

How can sites override the breakpoints?

As noted above, there's no easy way to customise the breakpoints via PHP hooks or in the WordPress dashboard customizer.

There are a couple of slightly hacky options:

  • Build a child theme that uses the Storefront source code as a scss library, override the variables, and recompile the child theme css whenever Storefront is updated.
  • Fork Storefront, override the variables (e.g. in another file), and recompile whenever Storefront is updated.

How could we improve this in a future version of Storefront?

We could move the responsive styles into PHP, and expose hooks or customizer UI for changing the breakpoints. This is not a great solution, as css-in-php is tricky to maintain and we lose the advantages of using SCSS.

I looked into using CSS variables, but they cannot be used for media queries.

If anyone has other ideas or info – please comment.

haszari avatar Jun 08 '20 03:06 haszari

Hi, as I understand, in 2018 in Storefront were .scss files. I tried to find them, but here's only style.css in wp-content/themes/storefront. I found here @media (min-width: 768px) and changed the value but it doesn't do anything. Help me please.

edddwin avatar Jun 08 '20 17:06 edddwin

I just had an idea of which I'm not sure if it's genius or nuts. I thought by myself, what about creating four (resp. eight) different styles:

  • phone.scss → phone.css
  • tablet.scss → tablet.css
  • laptop.scss → laptop.css
  • desktop.scss → desktop.css

And then enqueue these styles based on break points defined in the customizer:

wp_enqueue_style('storefront-phone', 'phone.css', array(), false, get_theme_mod('styles_phone') );
wp_enqueue_style('storefront-tablet', 'tablet.css', array(), false, get_theme_mod('styles_tablet') );
wp_enqueue_style('storefront-laptop', 'laptop.css', array(), false, get_theme_mod('styles_laptop') );
wp_enqueue_style('storefront-desktop', 'desktop.css', array(), false, get_theme_mod('styles_desktop') );

Please note that the code above is not 100% accurate, but pseudo-code for demo purposes.

@jconroy, @haszari, @Aljullu & @tiagonoronha Does this sounds like something worth creating a prototype or would you say it's a rather pointless idea?

nielslange avatar Jun 09 '20 17:06 nielslange

Thanks for brainstorming solutions @nielslange !

And then enqueue these styles based on break points defined in the customizer:

I think the challenge here is that this wouldn't change when these media queries take effect - i.e the breakpoints.

Depending on how the media queries are set, you could implement some limited flexibility this way. For example, if tablet.css was defined as "up to" some pixel width, not enqueueing phone.css might cause tablet styles to apply on phones and smaller. However in this situation, if phone.css was enqueued and tablet.css not enqueued, the laptop/desktop styles would not apply to tablet.

So this allows a little flexibility, but not enough to make it worthwhile in my opinion. Especially since it could be quite an extensive change.

The only way to have dynamic (user tweakable) breakpoints that I know of is to generate the css dynamically using PHP. This is not practical in Storefront, as our styles are mostly implemented in scss.

haszari avatar Jun 14 '20 20:06 haszari

Hi, Do you guys have any news regarding setting custom breakpoints?

Franz333 avatar Feb 23 '21 14:02 Franz333

Is this ever going to be looked at? or has already been looked at perhaps?

iiLearner avatar Feb 25 '21 14:02 iiLearner

I'm looking at doing this now.. my client has a lot of buttons on the navbar, and the content gets reflowed well before the pre-defined breakpoint. It's not a good look. Has anyone come up with a sustainable solution?

Skateboardb avatar Apr 27 '21 15:04 Skateboardb

Please add this! It's been nearly three years now but such a basic possibility for customization.

ckanitz avatar Jul 07 '21 11:07 ckanitz

Please do something about this. For a realistic situation where menu has more than HOME & SHOP, it doesn't work well for mid-size devices, because the menu items begin to wrap to second row.

draney avatar Nov 29 '22 19:11 draney