Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use CSS grid for gallery styles #1246

Merged
merged 2 commits into from
May 3, 2020
Merged

Conversation

gooklani
Copy link
Contributor

Changes proposed in this Pull Request:

Updated gallery item styles to generate a block-level grid

Related issue(s):

@m-e-h
Copy link

m-e-h commented Dec 20, 2017

Unfortunately, for now, _s still needs to support IE11. 😞

@gooklani
Copy link
Contributor Author

I wish _s could get rid of zombie 🧟 browsers support any time soon.

@grappler
Copy link
Collaborator

Thank you @gooklani for the pull request.

From the code styling perspective, we use tabs and not spaces so that would need to be changed.

As we currently have CSS and Sass files, both would need to be changed.

Could you mention what browser support is needed for this feature so that we can discuss it?

A screenshot of the before and after would be helpful to see any changes.

Thank you!

@bahiirwa
Copy link
Contributor

For browser support, could the @supports (display: grid) {} rule help? Or use css hierarchy by implementing css grid before the older css rules to allow overrides.

@gooklani
Copy link
Contributor Author

  • Chrome - Full support as of March 8, 2017 (version 57)
  • Firefox - Full support as of March 6, 2017 (version 52)
  • Safari - Full support as of March 26, 2017 (version 10.1)
  • Edge - Full support as of October 16, 2017 (version 16)
  • IE11 - No support for current spec; supports obsolete version

Internet Explorer 11 will never be updated to the new specification, and this is why grid layouts are not supported in IE.

Here's the complete picture:
https://caniuse.com/#feat=css-grid

@bahiirwa good idea, the @supports CSS at-rule enables us to specify declarations which depend on a browser's support for one or more specific CSS features.

@grappler What do you think? Would you like me to implement this so far?
https://codepen.io/primalivet/pen/ryjKmV

@grappler grappler changed the title Updated gallery styles Use CSS grid for gallery styles Dec 29, 2017
@grappler
Copy link
Collaborator

I think it is good to use modern CSS features. As IE still has 3% market share we need to make sure there is a backwards compatible solution. Also there are a few mobile browser that do not support it also.

It would be good to get more feedback from Frontend Developers.

@mor10 has been pushing CSS grid. It would be interesting to hear his thoughts.

@mor10
Copy link
Contributor

mor10 commented Dec 29, 2017

Grid is the right layout module here. If a fallback is necessary, the best option is to provide non-grid rules as the default and wrap the grid rules an an @supports rule.

However, there's a philosophical question that needs to be addressed here which has implications beyond the gallery: Should grid be used as the primary layout module for _s as a whole? If it's used in the gallery, it should be used everywhere which means _s needs to be refactored substantially. This in turn begs the question of why _s should not use grid as it's primary layout module. The immediate answer will be backwards compatibility, but is this a good reason? Is it _s' job to delay implementation of modern best practices for the sake of backwards compatibility? My personal opinion is no. _s should provide a modern baseline for development and the individual theme developer who uses it has the responsibility of providing whatever backwards compatibility is required for their project.

@m-e-h
Copy link

m-e-h commented Dec 29, 2017

💯 for refactoring _s layout as a whole. Floats have needed to go for a while, IMO. #682

And grid is surely the way to go for that as it makes short work out of complex layouts. But for something as simple as this basic gallery where the items are equal in size, what's the benefit of grid over the current inline-block implementation or even flexbox?

I've not used grid a ton but it appears both the behavior and the amount of code would be equal with this PR. Is that correct?

@bahiirwa
Copy link
Contributor

@mor10 that personal opinion makes sense. It defines a starter theme. Not completing the job for developer.

"implementation of modern best practices" should be key and where possible we should do backward compatibility.

@LittleBigThing
Copy link

Great idea to use CSS grid for the gallery and maybe for the whole _s theme.
I have 2 possible contributions on the discussion:

  1. How would using Grid affect Jetpack’s gallery styling? If it would at all. And other popular plugins interacting with the gallery.
  2. It seems to me that implementing grid for the whole _s theme instead of just the galleries could also be interesting since there is not a lot of layout stuff except for the floats for the sidebars and the main menu. We might work with optional SASS partials that can be commented out: a partial using floats if backwards compatibility is needed and one with Grid for more modern/adventerous solution. Even something similar using Flexbox for the navigation menu.

@gooklani
Copy link
Contributor Author

CSS Grid solves the layout structure problem by allowing designers to control both columns and rows simultaneously and in addition to that, you would be able to use Grid Gap to manage the spacing between the elements instead of tricky implementation of margin or padding.

@m-e-h I'm not sure why you are strictly taking sides against this grid implementation but to me being on the cutting edge of development is something we should want to do from anywhere or anyplace we could.

I assume this could be a start of something new and we can extend it to cover all aspects of the theme layout eventually.

@bahiirwa
Copy link
Contributor

On hind sight, there were issues to do with implementing framework like bootstrap etc in _s. Common consensus was leave that to developer. Doesn't using grid in the whole of _s going to brig issues with a developer choosing to use a CSS framework?

@mor10
Copy link
Contributor

mor10 commented Dec 29, 2017

@m-e-h like @gooklani says, using grid for the gallery opens the door for more advanced layouts, and more responsive ones too. For example, it would not be hard to make a gallery layout where some of the images are twice the size of others, and even make this dependent on how many images are in the gallery. It also makes it easier to style the gallery as a whole (because it wraps and clears properly) and gallery items individually.

@mor10
Copy link
Contributor

mor10 commented Dec 29, 2017

I have a fully refactored version of _s set up for grid in a private repo already. I can clean it up and submit it as a pull requests next week so you can all take a look. A lot is changed including nesting, clearings, and other features.

@mor10
Copy link
Contributor

mor10 commented Dec 29, 2017

@bahiirwa CSS frameworks like Bootstrap and Foundation were introduced to provide a solution to the lack of proper grid layout tools on web platform. Now that CSS Grid is live, the framework approach of complex HTML-based grids is no longer recommended, and actively works against the way the web works. Some frameworks will adopt grid as their layout module. Others will stick with old methods and will hold bot themselves and the web back as a result. In my opinion it would be counterproductive to avoid grid to preserve support for outdated methods.

@samikeijonen
Copy link
Contributor

samikeijonen commented Dec 29, 2017

I'm all in for using Grid everywhere even if it's pretty basic stuff in _s. Also noting that I'm 100% sure _s is going to be "Gutenberg ready" (#1248) in 2-4 months.

@Ismail-elkorchi
Copy link
Contributor

Ismail-elkorchi commented Apr 23, 2020

Hi @gooklani 👋 ! Would you still be interested in updating this PR now that #1251 was merged ? If not, no worries, I can pick up the work where you left off if you want, just let me know.

Updated gallery item styles to generate a block-level grid
@Ismail-elkorchi Ismail-elkorchi merged commit 50ce93c into Automattic:master May 3, 2020
dsgreen added a commit to dsgreen/_s that referenced this pull request Sep 9, 2020
* 'master' of https://github.com/Automattic/_s: (92 commits)
  Remove PHPCS Ignore Around $content-width (Automattic#1450)
  Use _S_VERSION constant when enqueuing customizer.js (Automattic#1445)
  Update composer and node dependencies (Automattic#1444)
  Add missing s in languages directory name (Automattic#1442)
  Exclude alignment classes from RTL conversion (Automattic#1435)
  Add new required header fields for style.css (Automattic#1432)
  Remove redundant font-size declarations (Automattic#1434)
  Refactor navigation.js to Javascript ES6 (Automattic#1423)
  Delete the custom bundle script in favor of an npm package (Automattic#1433)
  Fix small typo (Automattic#1428)
  Re-organize SASS structure (Automattic#1425)
  Add a SASS watcher command (Automattic#1427)
  Remove the skip link focus fix (Automattic#1424)
  Replace className.indexOf with classList.contains (Automattic#1422)
  Use CSS grid for gallery styles (Automattic#1246)
  Update README.md documentation (Automattic#1419)
  Add a bundle script to generate a zip file for theme distribution (Automattic#1417)
  Update npm dependencies (Automattic#1418)
  Float implies the use of the block layout (Automattic#960)
  Use the system font stack from WP admin (Automattic#1416)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants