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

Horizontal margin does not collapse (surprise), width full n border #112

Open
sanjarcode opened this issue Feb 14, 2024 · 1 comment
Open
Assignees

Comments

@sanjarcode
Copy link
Member

sanjarcode commented Feb 14, 2024

https://www.joshwcomeau.com/css/rules-of-margin-collapse/#only-vertical-margins-collapse-1 (other parts of this article may be wrong)

This is good to know.

Padding and borders work as expected. No surprises there.


Also, with w-100%, borders don't work as expected, i.e. because borders are additive, and w-full is applied to w, not W (calculated/used value). The fix is simple, but it's an indirect one. Stop using width-100% for "leftover space" (its not semantically correct or extensible).

The whole issue is regarding setting the width to all of the "left-over" space.
And w-100% is the wrong operator here, the correct one is display: block (if you're flex, you have block already)
So doing full width with border inside is simple, set display: block.

display: block; // or no need if display flex already
border: 10px solid black;

Sandbox for both things: https://codesandbox.io/p/sandbox/margin-vs-padding-4rwyjw

@sanjarcode sanjarcode self-assigned this Feb 14, 2024
@sanjarcode sanjarcode changed the title Horizontal margin does not collapse!, width full n border Horizontal margin does not collapse (surprise), width full n border Feb 14, 2024
@sanjarcode
Copy link
Member Author

Todo: is this horizontal collapse absent inconsequential?

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

No branches or pull requests

1 participant