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

Body classes for "first" blocks are super helpful, and "last" block classes could be helpful too. #345

Open
jonschr opened this issue Apr 23, 2020 · 2 comments

Comments

@jonschr
Copy link

jonschr commented Apr 23, 2020

This is my probably pretty clunky solution for outputting as body classes the alignment and name of the last block on the page.

https://gist.github.com/jonschr/f56701aebf858fb0733ebc0f49e8b478

Just wondered if you might implement something like this, since having body classes for the last block on the page/post/whatever can be quite helpful (for setting bottom padding on the content area, for example).

@jonschr jonschr added the bug label Apr 23, 2020
@jb510
Copy link

jb510 commented Apr 23, 2020

Im curious why :first and :last pseudo classes aren’t sufficient for this?

@jonschr
Copy link
Author

jonschr commented Apr 24, 2020

So, my use case is that on many of my sites I'm building using atomic blocks for some basic layout elements – so if the final block within .entry-content is a full-width ab-container, then I'll want .entry-content to have no margin on the bottom. However, if the last child is a paragraph or list or image, then I'll want a default margin to apply.

The :last classes actually don't apply very consistently here regardless. For example, when logged into the site, the edit page/post link is actually the last element, but when logged out, the final block is the last element. There are other situations that can crop up as well, where (for example) I've seen that sometimes comments with trackback information are injected after the last element of the .entry-content area, which I believe can affect usage of the :last pseudoelements (not sure where that's coming from, but you can see an example if you inspect this blog post: https://elod.in/contextual-styling-in-the-gutenberg-editor/)

The styling would be done more cleanly if a body class let me target the .entry-content directly.

That make sense?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants