-
Notifications
You must be signed in to change notification settings - Fork 682
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
[css-nesting-1] Should code portability trump coding habits wrt nesting syntax? #8029
Comments
I am confused by this statement.
I don't think any authors will like writing this at the end of a declaration.
In general I also find that typing I know that writing It falls apart with different formatting : div {
color: red;
} {
input { margin: 1em; }
} But I think this style is more realistic with how the feature would be used. |
I think @argyleink was confused by that statement, too. Here is an example of HTML/CSS you might find today: (I just took it from the table spec) <ul class="table">
<li><b>One</b><i>1</i></li>
<li><b>Two</b><i>2</i></li>
<li><b>Three</b><i>3</i></li>
</ul>
<style>
ul.table { display: table; }
ul.table > li { display: table-row; }
ul.table > li > * { display: table-cell; }
</style> Let's say that you inherit that code, and realise that it's not such a good idea to use the "table" class that way in your entire codebase, and you want to limit to a section of your site that contains the articles from the legacy system. You can take the CSS code, prepend :where(article.legacy) {} {
ul.table { display: table; }
ul.table > li { display: table-row; }
ul.table > li > * { display: table-cell; }
} Now, with the current option, proposal 3, this is not sufficient. You have to go and find all selectors that were starting with an indent, and fix them. :where(article.legacy) {
& ul.table { display: table; }
& ul.table > li { display: table-row; }
& ul.table > li > * { display: table-cell; }
} This is a manual operation that requires O(n) steps for the author. Each selector needs to be inspected, and then prepended with a '&' symbol if needed. This operation is error-prone and takes time, for something which I expect to be a very common refactoring. Plus, now, if you want to go back to an independant stylesheet (because, say, you moved to web components and isolated the legacy content there), you have to go back and remove all the This is also true if you move from or to
Yeah, that's true. I don't find that other way of writing it that bad, but it does feel less compact. I'd like to note that the examples for the first spec also use artifically-shortened forms though, like
I would also like to point out that with autocompletion these days, you hardly ever write a |
Thank you for elaborating, I know understand what the statement intended :)
I find it difficult to weight these correctly. Much more common to have existing blocks and add something nested inside of it.
There are proposals to give
Not saying that that is a reason not to pick 4 or 5.
Ah, yes, I forget about that because I disable this behavior.
Could even be a ligature like we have for |
We closed this issue after polling developer's opinion on the issue. Only around 20% of developers prefered not keeping the SASS-like syntax to avoid suffering from code portability issues, and about half of the remaining 80% advocate for a mandatory prefix before selectors, which destroys any hope of code portability. Based on this, we can assume a 20% vs 40% ratio against trade-offs for code portability, which makes the efforts of option 4 and 5 moot on this aspect. I'm closing this issue as a result. |
As a follow-up from #7834, the question of the "same-brace-but-inconsitent-prefixing" (Proposal 3) vs "other-brace-but-consistent-prefixing" (Proposal 4) was left open. Proposal 3 is described in the current editor draft. The presentation of Proposal 4 and the related discussion can be found here: #7834 (comment). Proposal 5 can be found here: #7970
The main advantage of Proposal 3...
The main advantage of Proposal 4...
The main advantages of Proposal 5...
Apart from the requirement to put the rules in another brace, the syntax between the three proposals looks remakably simliar, as can be seen in the following examples:
Regarding the question of nested rules in the style attribute, I would rather have rules contained in a
<style>
element where they can receive the space needed. There is a proposal for this already, for instance:Otherwise, we can also put them in another attribute named cssRules="..." which contains the content of the second (rule) block.
Anything I missed in the discussion?
The text was updated successfully, but these errors were encountered: