-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Try columns with grid and CSS vars #19297
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
Conversation
|
hm.. It could also be as simple as grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));That would simplify the code a lot and there would be no need for the css-var or calculating how many columns there are etc. |
@aristath I'm afraid we can't use |
f403d79 to
fbb5227
Compare
fbb5227 to
c4d0a0d
Compare
|
This seems promising! I like the fact that unset columns mostly stay proportional. In testing I had a few observations (tested using Twenty Nineteen):
|
draganescu
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This works good! 👏 Added just some minor comments.
| <RangeControl | ||
| label={ __( 'Percentage width' ) } | ||
| value={ width || '' } | ||
| initialPosition={ 0 } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When is this visible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be visible when a column has no explicit width set.
@talldan I tried this as well and the sizes remained the same. Although there is some flicker and i guess there remains an impression of the columns not being equal afterwards. Also can we fix this weird state when the number next to the range control is empty? |
|
@talldan I have updated this to use |
|
@tellthemachines Hmm, I seem to end up with really narrow columns when adding the block for some reason: |
There were auto-margins on the inner columns. I've removed them and made some further margin-related tweaks. Everything should look as before now 😄 |
|
Noting that I remarked at #18416 (comment) with some concerns about reimplementing Columns using Grid. |
|
Closing this PR as it will require a substantial re-write to fit with the recent changes to the columns block. |


Description
This is a proposal for drastically simplifying Columns/Column blocks styling with CSS grid and variables.
The main reason for this is getting rid of the need to set inline styles in blocks as much as possible, because inline styles break the resizable editor (#19082).
This work will incidentally also fix #18416 and #19112 / #19515.
Column width is now set in the columns block with CSS grid, but each column still computes its own width and may reset the width of the adjacent columns if total column widths exceed 100%.
Columns without an explicit width are set to 1fr, so remaining width is distributed equally among all columns without explicit widths.
I have added a basic flexbox fallback for IE, because this grid implementation depends on CSS variables to work. This means that IE users won't be able to preview columns with custom widths.
This setup is much easier to override by themes, because it doesn't depend as much on inline styles. E.g. themes can now cleanly override the grid-gap width with a single line of code.
How has this been tested?
Tested across browsers. IE maintains basic functionality.
Screenshots
Types of changes
Checklist: