A little LESS puzzle

Hi people! What do you think of a little puzzle to wake up your neurons? I think I’ve found something tricky enough to worth a blog post and a little challenge about it.
First of all, this will be a LESS puzzle, so if you’re really unfamiliar with this…

Hi people! What do you think of a little puzzle to wake up your neurons? I think I’ve found something tricky enough to worth a blog post and a little challenge about it.

First of all, this will be a LESS puzzle, so if you’re really unfamiliar with this CSS preprocessor, I think you might feel a bit lost here. Sorry! 🙁

What are the requirements

So the main idea is to enable a Google Web Font using a variable to have only one occurrence of the font name without leaving the stylesheet. Let me explain the requirements a little better:

  1. Pick a Google font here,
  2. Click on “Quick use”, then @import, and copy the given URL to your clipboard,
  3. Open CodePen, click on “New pen” and pick LESS as a CSS preprocessor,
  4. Create a variable for the font name, like this @my-font: "NameOfMyFont";,
  5. Import the font from Google CDN with @import url() using the variable as the font name in the URL,
  6. Give any element (

    would be good) this font.

Bonus: make it work with compound font names (such as “Roboto Condensed”).

Accustomed to Sass like me will wonder where is the difficulty in this little exercise. Problem is LESS is extremely annoying when it comes to both url() and string concatenation. I partially covered the topic in this article.

/* Sass version */

$my-font: 'Merriweather';
$url: 'https://fonts.googleapis.com/css?family=#{$my-font}';

@import url($url);

h1 {
font-family: $my-font;
}

I struggled about one hour on this and couldn’t make it work. All my respect to the one who will find the solution.

Good luck!

Conclusion (edit January 26th, 2013)

Loïc Giraudel (secondarily my dear brother) pointed out a thread on GitHub mentioning that what I called a “puzzle” is in fact a real bug reported more than a year ago.

However as of today, there is no fix for this neither is there a workaround. So unless anyone comes up with a solution, this is currently not possible unfortunately.

Plus, the people behind LESS imply fixing this bug would require a large amount of work and deep code restructuration.

No luck.


Print Share Comment Cite Upload Translate
APA
Hugo “Kitty” Giraudel | Sciencx (2024-03-28T12:44:14+00:00) » A little LESS puzzle. Retrieved from https://www.scien.cx/2013/01/21/a-little-less-puzzle/.
MLA
" » A little LESS puzzle." Hugo “Kitty” Giraudel | Sciencx - Monday January 21, 2013, https://www.scien.cx/2013/01/21/a-little-less-puzzle/
HARVARD
Hugo “Kitty” Giraudel | Sciencx Monday January 21, 2013 » A little LESS puzzle., viewed 2024-03-28T12:44:14+00:00,<https://www.scien.cx/2013/01/21/a-little-less-puzzle/>
VANCOUVER
Hugo “Kitty” Giraudel | Sciencx - » A little LESS puzzle. [Internet]. [Accessed 2024-03-28T12:44:14+00:00]. Available from: https://www.scien.cx/2013/01/21/a-little-less-puzzle/
CHICAGO
" » A little LESS puzzle." Hugo “Kitty” Giraudel | Sciencx - Accessed 2024-03-28T12:44:14+00:00. https://www.scien.cx/2013/01/21/a-little-less-puzzle/
IEEE
" » A little LESS puzzle." Hugo “Kitty” Giraudel | Sciencx [Online]. Available: https://www.scien.cx/2013/01/21/a-little-less-puzzle/. [Accessed: 2024-03-28T12:44:14+00:00]
rf:citation
» A little LESS puzzle | Hugo “Kitty” Giraudel | Sciencx | https://www.scien.cx/2013/01/21/a-little-less-puzzle/ | 2024-03-28T12:44:14+00:00
https://github.com/addpipe/simple-recorderjs-demo