by jraph · 3y ago · 0 comments
.stack > * + * {
margin-block-start: 1.5rem;
}
I got it immediately because I think I've been doing something similar for a while. I identified the problem it solves. I understand that if you haven't encountered the situation, it's probably hard to decipher.It reads like: apply a top margin to all direct children that are not the first one.
I write it like this:
.stack > :not(:first-child) {
margin-top: 1.5rem;
}
I probably should start using -block-start. I'll keep my selector though I think.I didn't know about the default value parameter of --var, I'll probably use it too.
So do I, I am somehow wired to think "* is going to be very bad for performance because now the rendering engine will need to apply this bunch of rules to any and every element on earth, which might not be only overkill, but which also might have undesirable side effect."
It might not really apply here but the feeling is present.
https://www.reddit.com/r/web_design/comments/5u6e7b/comment/...
margin-block-* and margin-inline-* (versus margin-{top,right,bottom,left}) are more generic and take into account the writing-mode, direction, and text-orientation.
https://developer.mozilla.org/en-US/docs/Web/CSS/margin-inli...
Notably, for instance, if you want to support both rtl and ltr languages, margin-inline-start (instead of margin-left) will behave correctly and put the margin at the correct side.
If you ask me, it's a step towards specifying/conveying the intent and not hard-coding the look.
* + * is 0,0,0.
:not(:first-child) is 0,1,0.
:where(:not(:first-child)) would take it back to 0,0,0.