studiopress / genesis-sample

This is the sample theme created for the Genesis Framework.
https://demo.studiopress.com/genesis-sample/
530 stars 283 forks source link

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

Open jonschr opened 4 years ago

jonschr commented 4 years ago

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).

jb510 commented 4 years ago

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

jonschr commented 4 years ago

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?