Manual talk:Coding conventions/CSS/Archive 1

Comments about colors
Does it make sense to anybody but me to demand writing comments about numbered color values in CSS? --Amir E. Aharoni (talk) 19:35, 25 July 2012 (UTC)


 * Everyone who writes CSS probably knows what #000 and #FFF stand for, but I for one don't know that #C71585 stands for "MediumVioletRed" without looking it up on the English Wikipedia (or some other CSS resource). So yes, I wholeheartedly support using comments to write out the color name in plain English. After all, comments are cheap, just like space. --Jack Phoenix (Contact) 13:55, 26 July 2012 (UTC)

LESS
The LESS section is more a guide about LESS than a coding conventions set of guidelines.

Someone has an objection to move most of the section to a Manual:LESS page? --Dereckson (talk) 21:32, 30 October 2013 (UTC)

Prefix mixins with mixin- ?
It's hard to distinguish .foo { } with .foo { .foo; } especially if you are new to LESS. I think it would be in everyones interest to prefix all mixins with mixin- to help with readability and to place mixins at the top of a file. e.g. .mixin-foo { } .foo { .mixin-foo; }

Thoughts? Jdlrobson (talk) 22:25, 7 August 2014 (UTC)
 * +1. You've convinced me this is a good idea. I don't have a strong preference on the prefix, or whether mixins have to go in the top of the file.  But it seems like a useful convention overall. Superm401 - Talk 00:03, 9 September 2014 (UTC)

Add spaces around mixin parameters ?
I'm not sure about one of the existing code conventions. I think it is useful to be able to more clearly distinguish between and In the second case we are dealing with a mixin and I would recommend that using spaces would make it clearer. e.g.

Just a suggestion. Jdlrobson (talk) 15:57, 9 April 2014 (UTC)


 * I think that's a very good idea and that, because ResourceLoader is minifying the files anyways, we should also discuss about applying whitespace for CSS property values with brackets like URIs to align CSS brackets notation with PHP and JS Coding Conventions.
 * Citing from W3C – "The format of a URI value is 'url(' followed by optional whitespace followed by an optional single quote (') or double quote (") character followed by the URI itself, followed by an optional single quote (') or double quote (") character followed by optional whitespace followed by ')'. The two quote characters must be the same." Resulting in:
 * --VEckl (WMF) (talk) 14:53, 21 July 2015 (UTC)
 * Agreed, let's update. ESanders (WMF) (talk) 18:19, 2 October 2015 (UTC)
 * --VEckl (WMF) (talk) 14:53, 21 July 2015 (UTC)
 * Agreed, let's update. ESanders (WMF) (talk) 18:19, 2 October 2015 (UTC)

Less and future CSS variable naming convention
We are currently missing a naming convention for Less and somewhen future CSS variables (custom properties). We already have conventions for PHP variables or JavaScript variables. It's time to agree on and implement a CSS/Less variable naming convention.

Throughout projects there's currently a pretty wild mix, for example in Vector:

or mediawiki.ui:

or Minerva:

A new proposal
The duplication of property name and property as variable name in applied property values is IMHO verbose and redundant. I'd propose to take popular and widely-used Emmet (section CSS) as base for shortening of property into consideration. Variables are (with the very exception of calculations and size values) almost always belonging to a certain CSS property, therefore the property doesn't need to be repeated. Even when the variable's value change, it will always be connected to a certain property!

When it comes to the variable names, I'd suggest to follow the same formatting regimen like CSS' built-in and the CSS vars standards document draft and use  as separators. Although camelCase is used across PHP and JS coding conventions, it's not common in CSS. Here's some more food for thought. To the structure of the variable naming, I think it's a good idea, to follow the HTML5 classification, so no, but   and.

CSS namespaces useful?
Naming is hard and designing CSS for scalability is even harder. CSS namespaces (example) have in my experience a great potential to gain speed working with disperse people and projects on front-end. — Preceding unsigned comment added by VEckl (WMF) (talk • contribs) 04:43, 12 September 2015 (UTC)
 * Would "Hungarian notation for CSS" be an appropriate TL;DR summary of that link? Anomie (talk) 13:24, 14 September 2015 (UTC)

Gzip heatmap of lowercase color values
Out of curiosity I wanted to see for myself how lowercased, shorthand notated color values of 2015-08's Vector CSS would look like in gzthermal heatmap, mentioned on color property section on the guidelines article:

Gathering ideas of what base unit values to use where/when?
Copy from IRC for now. Will work on some ideas soon. 01:05  we're talking about the content's font-size? 01:05  in which case, it's already compatible. it works on Vector and MonoBook, which have different font-size 01:05  if we're talking about the font-size for VE's own UI, then no one has tried yet, it's still using 0.8em (=12.8px) on both Vector and MonoBook, afaik [...] 01:06  (MonoBook uses 0.8em for content, Vector uses 0.875em=14px for content) 01:09  MatmaRex: trying to experiment with ideas getting out of the for me not-satisfying pixel rounding of applied 'em's 01:10  Volker_E: oh, hmm 01:10  Volker_E: i'm not sure if you realize, but thesituation there is far more interesting 01:10  :D 01:11  MatmaRex: in which way? :} 01:11  Volker_E: the MediaWiki theme of OOjs UI is currently developed with font-size of 0.8em (12.8px) in mind 01:11  since that was the font-size of Vector when it started to be developed 01:11  then font-size of Vector was changed, but the theme did not get updated. 01:12  so right now, in the demo, we still have 0.8em, but in the actual MediaWiki, we have 0.875em. this is easily noticeable as blurry icons (unless you have an absurdly retina screen) 01:12  MatmaRex: yeah, great scheme of hard-to-maintain dependency failures 01:12 — Volker_E shudders 01:13  but not in VisualEditor! it has some custom CSS to make the font-size inside its UI 0.8em, because no one wanted to update the theme itself to 0.875em 01:13  this was not a problem, until we started using the theme outside of VE [...] 01:13 <MatmaRex> but if we try to fix the theme now, VE will look weird, so we have to update it simultaneously 01:13 <James_F> Ideally we should make everything use a font-size of 1em and just change what the base font size is. 01:14 <James_F> (Heresy!) 01:14 <MatmaRex> and then other things will no doubt break. Flow also uses OOUI, and also has font-size hacks, but only in some places, because it was done inconsistently [...] 01:14 <Volker_E> Ideally would be relying on `rem` but as we have no superpowers people come up with weirdest default settings 01:14 <Volker_E> *we would 01:15 <MatmaRex> the only real problem with the font-size changing under us is that icons become blurry, evertything else should scale fine 01:15 <MatmaRex> but the nested hacks upon hacks are a problem, the last time we touched it, in VE, inspectors inside dialogs balooned to twice the usual size for some reason 01:15 <Volker_E> MatmaRex: I disagree, there are (due to shortcomings in browser rendering engines) several issues around pixel rounding errors 01:16 <Volker_E> MatmaRex: like box-shadows, or border-radius weird effects 01:16 <MatmaRex> oh yeah, that's true, but i personally think that is just hopeless. :) 01:17 <Volker_E> MatmaRex: what hacks upon hacks are you referring to? 01:18 <Volker_E> MatmaRex: hacks to get inherited em in balance again? 01:18 <MatmaRex> yes 01:18 <MatmaRex> in VE, modules/ve-mw/init/styles/ve.init.mw.DesktopArticleTarget-vector.css and similar 01:19 <MatmaRex> Volker_E: there is at least one bug in VE caused by that, if you look closely, the page heading/title is smaller in edit mode. 01:20 <Volker_E> MatmaRex: for a UI (here a theme) where I have full control about root elements `rem` is my best bet from current perspective 01:21 <Volker_E> MatmaRex: for an extension it's much more difficult 01:21 <Volker_E> MatmaRex: did anyone ever look into using px for all browsers aside from IE 01:22 <MatmaRex> Volker_E: no idea. 01:22 <Volker_E> MatmaRex: which would mean that modern zoom applies in modern browsers 01:22 <Volker_E> MatmaRex: but in text-zoom only mode you're targeting size adaption with em... 01:24 <MatmaRex> Volker_E: i don't know. the decision to use ems predates me, it looked reasonable to me and i never questioned it. if anyone knows more about this, it's Trevor 01:26 <Volker_E> MatmaRex: ok, hopefully I've got enough time to prepare some historical anecdotes, code examples and pro&con summaries. ;) That should prob get on the next FE std group list. 01:26 <Volker_E> MatmaRex: Thanks for the insights!

How much of this is actually true?
Looking at core and what seem to be best practices in current extensions and skins, a lot of this just doesn't apply, and sometimes for very good reason. So how much of these conventions are, er, actually correct? -— Isarra ༆ 17:42, 30 October 2015 (UTC)
 * What are "sometimes very good reasons" for not applying on which of the topics? Knowledge and best-practices have to be shared before being applied. And even if they are shared, on best-practices like color name guidelines, there's currently no strict enforcement of those conventions. If you find problems within the current conventions, here on the talk page seems to be a good place to raise them. --VEckl (WMF) (talk) 04:39, 5 November 2015 (UTC)
 * So... this page is supposed to be real? -— Isarra ༆ 07:38, 5 November 2015 (UTC)
 * Well, you know how it is with reality and its perception… it's a wide field. But yes, that's IMHO the place to raise general issues/ideas on best approaches/guidelines around CSS/Less outside of Phabricator. --VEckl (WMF) (talk) 01:28, 6 November 2015 (UTC)