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

Remove margin-bottom on last child #557

Open
pietz opened this issue Jun 3, 2024 · 2 comments
Open

Remove margin-bottom on last child #557

pietz opened this issue Jun 3, 2024 · 2 comments

Comments

@pietz
Copy link

pietz commented Jun 3, 2024

Please search for duplicate or closed issues first.

Describe the issue

PicoCSS uses margin-bottom on many elements to create spacing to the next element. This makes sense, but you probably want to remove it from the last child within a div to not create trailing white space that might stack over multiple layers.

Current Behavior

For example, if you create a form in a card that ends with a button:

Screenshot 2024-06-03 at 09 36 20

<article>
    <input type="text" />
    <input type="text" />
    <input type="submit" />
</article>

The input fields introduce a margin-bottom to create spacing to the next element. Makes sense.

However, the button also adds a margin-bottom which doesn't help with anything. It just makes the card look unbalanced because there's more room at the end than in the beginning.

To make things worse, this problem usually stacks if you have a form within a card, within a column, within a grid, within a container. It just creates a lot of trailing white space that's not needed and doesn't look good.

Expected Behavior

I think this is what it should look like:

Screenshot 2024-06-03 at 09 38 05

I created a workaround where I manually add "margin:0" to the last element but I think it should be solved within PicoCSS.

Environment

Example: MacOS, Firefox, PicoCSS 2.0.6

@harith-hacky03
Copy link

I am eager to work on it. Can you please assign me?

@coezbek
Copy link

coezbek commented Oct 4, 2024

Workaround if your last element is the last child:

/* Remove margin-bottom from last button in a form */
[type=submit],
[type=reset],
[type=button] {
  &:last-child {
    margin-bottom: 0px;
  }

  /* Also remove if next input after button is a hidden input */
  &:has(+ [type=hidden]) {
    margin-bottom: 0px;
  }
}

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

3 participants