• Stars
    star
    305
  • Rank 136,048 (Top 3 %)
  • Language
    CSS
  • License
    MIT License
  • Created almost 10 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Flags of the world with only one div

CSS Flags

Recreating all the flags of the nations of the world in pure CSS, using only one div per flag.

You can see it live on https://pixelastic.github.io/css-flags/

This side-project has no real-world application, it was just an exercise to push the boundaries of what I know about CSS. Trying to use the language to do things it wasn't meant to do in the first place taught me a lot about the language.

Running the project locally

bundle install
npm install
npm run serve

The website will then be available on http://localhost:4001/.

Contributing

If you've spotted an issue with the rendering of a specific flag or if you know how to do one of the missing flags, I'm open to pull requests.

Compatibility

I've only tested the rendering on Chrome and Safari so far. I plan on making it cross-browser but I need to add visual non-regression testing first.

Sources

To create the flags, my three most important sources were the Wikipedia, CRWFlags and Vexilla Mundi. CRWFlags contains valuable information about every flag history, allowing me to better understand how they were constructed. Vexilla Mundi contains handy construction sheet images with dimensions and angles.

I also used this list to get the list of all countries with their three letter ISO code.). This website also gives a nice overview.

Not all flags have an exact definition of the colors to use. Best case scenario, we have the official RGB/Hexa (or even Pantone) name of the color. Worst case, we have nothing and have to use the color used on the Wikipedia or Vexilla Mundi, even if it is not the official one.

Icons

To be able to display some of the very specific symbols used on some flags, I had to craft my own icon font, using icomoon.io.

I had to find svg versions of all the symbols used. Sometimes the symbols already exists in the UTF8 table, so I just have to grab them from existing fonts (or use utf8icons.com).

But more often, I had to use Vexilla Mundi. The website provides nice png images of all the symbols. Unfortunately, the symbols they provide are already colored, and I needed them black to use in the font so I was able to define the color myself.

The following script will do exactly that:

convert input.png \
        -alpha off \
        -fill black \
        -colorize 100 \
        -alpha on \
        output.png

I then had to trim the image to remove any whitespace left around the symbol:

convert input.png -trim output.png

Then, I need to convert the png to an svg. I couldn't find any commandline tool giving satisfying results, so I had to use an online service to do it: online-convert.com

Once I got the svg, it is just a matter of uploading it to icomoon, center the symbol, scale it and adjust the border. I also used the reserved namespace in the UTF8 table for custom characters. And finally exported the font.

FAQS

You're using half pixels. That does not make any sense.

Ok, that's not really a question, but I'll explain anyway.

I try to use percentage as much as I can, when it makes sense. Percentage are relative to either the width or the height of the flag. When doing a tricolore flag, I will use 33.33% as the width of each stripe for example. But as soon as I need to draw a square that has the same width than height, I can no longer user percentage values, I need real, absolute, pixel values.

Related projects

img2css

http://github.com/pixelastic/img2css/

Commandline tool to convert any image (jpg or png) to full CSS. This will replicate all pixels of the initial image using numerous box-shadows.

This works wel but results in really heavy generated CSS (several MB), so I choose not to use it in this project.

pantone2hex

http://github.com/pixelastic/pantone2hex/

Commandline tool to get an approximation in hexadecimal of a Pantone color value. Really useful as Vexilla Mundi gives color values in Pantone.

Vexillum

https://github.com/talgautb/vexillum

Someone else had the same idea.

Tips and tricks

Here is an incomplete list of the tricks I had to use:

Invisible text-shadow

I sometimes put an invisible symbol in an after or before element (through color: transparent) and positioned it at top:0; left: 0.

Then I added several text-shadow to it, with a full color. Doing so helped in getting the coordinates right because everything is then relative to the origin 0,0.

first-letter / first-line

When I needed to add more than 1 symbol in an after/before, or if I needed the same symbol, but on different sizes, I had to be sneaky.

By setting a content of "XY\AZ" and then using both first-letter and first-line, I was able to independently target X, Y and Z. \A is the special character to add a new line in a content.

Doing so let me use three different symbols, with different color and sizes with only one pseudo-element.

It is impossible to apply any transform (like a rotation) on those elements, though.

TODO

This project is not over, there are still some elements that I would like to add:

  • Link to codepen to let users play with the code
  • Making it work on more browsers...
  • ...which implies that I need to add a visual testing framework on top if it
  • Adding the missing flags
  • Using a clip-path when only one star instead of a font
  • Building the font with npm instead of icomoon.io
  • Adding stars to Brazil
  • Doing the Nepal flag
  • Check if Lea Verou has a background pattern close to the British India
  • Add the Leather Pride flag as an easter egg

More Repositories

1

pokemonorbigdata

Is it Pokemon or Big Data ?
JavaScript
330
star
2

oroshi

x My dotfiles repo.
Shell
32
star
3

dconf-export

Export your dconf settings as an editable .sh file.
Ruby
21
star
4

fakeusers

JSON list of fake users including names, address and picture
Ruby
14
star
5

firost

> Toolbox for command-line scripts
JavaScript
9
star
6

vim-undodir-tree

Save vim undo files as /path/to/file instead of %path%to%file.
Vim Script
9
star
7

norska

🏔️ Custom SSG using Pug, Webpack, PostCSS and Tailwind.
CSS
8
star
8

algolia-indexing

Perform complex indexing operations with ease
JavaScript
7
star
9

datagouv-scrapper

Getting data from data.gouv.fr in a more easily readable format.
Ruby
6
star
10

pietro

π Utilities to split PDF files into smaller files, generate thumbnails and extract textual content.
JavaScript
6
star
11

prst

Pull Request Status Tracker. See your PR status live from your commandline, and get notified when all tests are done.
JavaScript
5
star
12

tedtalks-audio-list

List of all TEDTalks audio files, in various formats.
Ruby
5
star
13

programmingexcuses.sh

Generate a random excuse from the command line.
Shell
5
star
14

html-hierarchy-extractor

⚠ DEPRECATED Use algolia_html_extractor instead.
Ruby
4
star
15

img2css

Convert any .jpg or .png to a single CSS div
Ruby
4
star
16

meetup-random-user

Pick a random attendee from any meetup event
JavaScript
4
star
17

vcf-split

Split a monolithic vcard file into several files, one for each contact.
Ruby
4
star
18

parisweb

Recherchez dans l'ensemble des conférences et ateliers ParisWeb
Hack
4
star
19

sql-french-cities

Sql dump of the whole list of cities in France.
4
star
20

vit

⚠ WIP ⚠: git commands in a vim way
Ruby
4
star
21

blog.pixelastic.com

Source of the website available at blog.pixelastic.com
JavaScript
3
star
22

dotcss-onediv

The dotCSS logo in one single `<div>`
CSS
3
star
23

talk-css-flags

CSS
3
star
24

octo-webf-guidelines

Guide de bonnes pratiques de développement front, pour la tribu WEBF d'Octo Technology
CSS
3
star
25

mirror.css

‮Reverse all text of your webpage.
CSS
3
star
26

meetups.pixelastic.com

Source of the website available at meetups.pixelastic.com
JavaScript
2
star
27

meetup-friends.js

Improve meetup.com experience by providing a friend list.
JavaScript
2
star
28

golgoth

Ω Meta-package of my most used modules.
JavaScript
2
star
29

ebook-journey

Notes on the journey of a webdeveloper (re)learning languages and tools.
Ruby
2
star
30

img

Ruby
2
star
31

reddinx

Import all pictures from a subreddit in a format suitable for Algolia
JavaScript
2
star
32

spells

JavaScript
2
star
33

maps

Search for D&D maps for your next game
JavaScript
2
star
34

aberlaas

⛰️ Scaffolding npm projects with test, lint and release scripts
JavaScript
1
star
35

talk-serverless

HTML
1
star
36

algolia-app-diff

JavaScript
1
star
37

ensure-url-trailing-slash

Ensure the current url has a trailing slash
JavaScript
1
star
38

coriolis

≈ Aliases and helpers to handle a Kubernetes cluster from the commandline
JavaScript
1
star
39

solr-search

Search into the Solr user manual
HTML
1
star
40

anki-http-status-cats

Anki deck for learning HTTP Status Code using cats.
1
star
41

landscapes

Sourcecode for the https://projects.pixelastic.com/landscapes website.
JavaScript
1
star
42

playlist2json

Download a json version of a Youtube playlist
Ruby
1
star
43

humantalksify-video

Simple script to add the HumanTalks sponsor overlay to a video
Ruby
1
star
44

norska-theme-docs

Pug
1
star
45

gilmore

Glorious git and GitHub toolbox
JavaScript
1
star
46

armory

Browse magical items lore from various videogames
JavaScript
1
star
47

youtube-playlist-urls

JavaScript
1
star
48

front-build-comparison

Comparison of several front-end build tools (grunt, gulp, brunch, npm, make)
HTML
1
star
49

img2term

Display any image in your terminal
Ruby
1
star
50

talk-public-speaking

Tips & Tricks on how to improve your public speaking skills
HTML
1
star
51

transparentify

Remove the background of any image, using PhotoRoom API
JavaScript
1
star
52

tailwind-config-norska

DEPRECATED. This is now part of norska-css.
JavaScript
1
star
53

roleplay.pixelastic.com

Source of roleplay.pixelastic.com
Ruby
1
star
54

markdown-preview

Renders a preview of a markdown text in your browser.
HTML
1
star