I was impressed very much by @alvaromontoro's work

Drawing Togo's Flag with CSS
Alvaro Montoro ・ Nov 19
HTML
I add one
<div role="img" aria-label="Flag of Taiwan" class="flag taiwan"></div>
CSS
I used the same method as @alvaromontoro to create a basic background of the Taiwan flag: red background color with a blue rectangle on the top-left.
.flag.taiwan { aspect-ratio: 3 / 2; height: 500px; position: relative; background: linear-gradient(rgb(19, 53, 129) 0 0) 0 0 / 50% 50% no-repeat, rgb(205, 44, 36); }
The Sun
Ok, the easiest part is finished. Now it is time for the real deal. The sun on the flag.
It looks pretty complicated, with 12 beams and a circle at the center. How is it possible to use the pseudo elements, ::before and ::after to draw them? It feels like only the clip-path: path() is the only way to do that because path() can draw any shape we want. However, clip-path: path() has a fatal disadvantage: it's not responsive! That means the flag can have only one size if I choose that approach.
I started googling many SVG files of Taiwan flag. And I noticed that they only use 2 elements to represent the sun.
- a white 12-beam star
- the white circle with a blue border
When the circle is put down on the center of the star. It looks like there are 12 beams surrounding the circle with a desired gap. So smart!. It seems like designers have already figured out this clever way to draw that sun. By taking this approach, I can use ::before as the circle and ::after as the star.
12-beam star
It is very easy to find SVG files of Taiwan flag. Unfortunately, all the stars are drawn by path(). It's because path() is responsive when it is in a real
It is a really difficult problem. My final solution is really to calculate all the positions of all the points of the 12-beam star? I utilized this fantastic online SVG Path Editorhttps://yqnn.github.io/svg-path-editor/ to visualize all points in the path.
And I asked my dear brother who is very good at math what are the positions of the rest of the points. He used mathematica to solve 12 linear equations and got all the points! ?
Then, I backed to the path editor to draw the outline of the star as the path and scaled it so it will be in a 100*100 scope.
I then convert all positions to percentages since it's already in 100*100 scope. As a result, we can display the star on the flag
<div role="img" aria-label="Flag of Taiwan" class="flag taiwan"></div>
The circle
The circle is relatively easier. However, my first attempt was using the border. It failed because the width of the border can only be px. I changed to use radial-gradient. The tricky part is that the percentage in radial-gradient needs to be the diagonal of the element so it also needs some math but it's not that hard.
.flag.taiwan { aspect-ratio: 3 / 2; height: 500px; position: relative; background: linear-gradient(rgb(19, 53, 129) 0 0) 0 0 / 50% 50% no-repeat, rgb(205, 44, 36); }
Result
The full CSS is
&::after { content: ''; position: absolute; top: 6.25%; left: 12.5%; width: 25%; height: calc(3 / 8 * 100%); background: white; clip-path: polygon(50% 0%,56.6987% 25%,75% 6.6987%,68.3013% 31.6987%,93.3013% 25%,75% 43.3013%,100% 50%,75% 56.6987%,93.3013% 75%,68.3013% 68.3013%,75% 93.3013%,56.6987% 75%,50% 100%,43.3013% 75%,25% 93.3013%,31.6987% 68.3013%,6.6983% 75%,25% 56.6987%,0% 50%,25% 43.3013%,6.6983% 25%,31.6987% 31.6987%,25% 6.6983%,43.3013% 25%);; }
You can also check out my work on codepen below
Hope you like it!
The above is the detailed content of Drawing Taiwans Flag with CSS. For more information, please follow other related articles on the PHP Chinese website!

CSS Grid is a powerful tool for creating complex, responsive web layouts. It simplifies design, improves accessibility, and offers more control than older methods.

Article discusses CSS Flexbox, a layout method for efficient alignment and distribution of space in responsive designs. It explains Flexbox usage, compares it with CSS Grid, and details browser support.

The article discusses techniques for creating responsive websites using CSS, including viewport meta tags, flexible grids, fluid media, media queries, and relative units. It also covers using CSS Grid and Flexbox together and recommends CSS framework

The article discusses the CSS box-sizing property, which controls how element dimensions are calculated. It explains values like content-box, border-box, and padding-box, and their impact on layout design and form alignment.

Article discusses creating animations using CSS, key properties, and combining with JavaScript. Main issue is browser compatibility.

Article discusses using CSS for 3D transformations, key properties, browser compatibility, and performance considerations for web projects.(Character count: 159)

The article discusses using CSS gradients (linear, radial, repeating) to enhance website visuals, adding depth, focus, and modern aesthetics.

Article discusses pseudo-elements in CSS, their use in enhancing HTML styling, and differences from pseudo-classes. Provides practical examples.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Notepad++7.3.1
Easy-to-use and free code editor
