Experiment: Try to change scope of classic auto margins.#34351
Closed
Experiment: Try to change scope of classic auto margins.#34351
Conversation
|
Size Change: -8 B (0%) Total Size: 1.04 MB
ℹ️ View Unchanged
|
7 tasks
Contributor
Author
|
No hearts were set on fire by this one, and since the gap solution has landed, I'll close this one for now. We can always revisit if it comes back. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR is mostly created for the discussion topic.
In classic themes, we have this rule to deal with:
It's been around for a while, and it exists to center blocks in a main column. Of course we've already encountered headaches with the specificity of this in nesting contexts, having to unset those margins.
In #32659 I tried to replace that with this:
That works wonderfully in that it reduces the specificity of that rule to barely anything. The problem is that in themes, blocks like List or usually set
margin-left: 0;, and there are commonly blanket rules that set the overall margin offigureto zero, which would both left align those blocks now that the specificity is reduced.The reason I'm back here again, though, is that we've reached a bit of a crossroads with this rule, and how global styles works. Let me walk through an example.
In the navigation block, you can insert menu items. These menu come with default margins:
margin: 0 2em 0 0;, and the specificity of this rule is kept low enough that you can easily write out your own custom menu item margins in theme.json to override and configure. This works great in block themes.However that same low specificity means that the auto margins win out, in this case, right-aligning the menu items:
The problem is, we can't increase the specificity of the margin rule in the navigation block, without also having to change the specificity of rules output by global styles. It's a bit of an arms race.
Ultimately the solution to the navigation block might be to use
gapinstead of margins (#32367). But the challenge above is likely going to emerge in the future as more blocks are refactored to leverage global styles. Hence this draft PR, which changes the classic auto margin rule to this new selector:.is-root-container > .wp-block. In my brief testing, this works as intended. But I'm sure there's something I haven't thought of.