Create Dynamic Shapes with FSCSS
If youโre looking to add some flair to your web projects, this FSCSS-powered shape generator is a lightweight way to create dynamic, colorful shapes with minimal code. Letโs dive into how it works and why itโs a neat tool for developers.
๐น The Code
Hereโs the complete snippet to generate 10 unique shapes with FSCSS:
<!-- Container for shapes -->
<section class="shapes" id="shapes"></section>
<style>
/* Import FSCSS initialization and themes */
@import(exec(_init themes))
/* Define arrays for shapes and colors */
@arr list[cross, star, diamond, cloud, teardrop, triangle, hexagon, trapeziod, crescent, arrow, square]
@arr colors[red, blue, green, orange, purple, pink, brown, teal, gold, violet, gray]
/* Style shapes using arrays */
.shape:nth-child(@arr.list[]){
%2(width, height [: 100px;])
clip-path: @event.shape(@arr.list[]);
}
.shape:nth-child(@arr.colors[]){
background: @arr.colors[];
display: inline-block;
}
</style>
<script>
// Dynamically generate 10 shape divs
const shapeContainer = document.getElementById("shapes");
for (let i = 0; i < 10; i++) {
const shape = document.createElement("div");
shape.className = "shape";
shapeContainer.appendChild(shape);
}
</script>
<!-- FSCSS CDN -->
<script src="https://cdn.jsdelivr.net/npm/fscss@1.1.6" async></script>
๐ Why Itโs Cool
FSCSS Magic
โ The @arr and @event directives let you loop through shapes and colors effortlessly, reducing repetitive CSS.
Dynamic & Scalable
โ The JavaScript loop creates
s on the fly, and FSCSS applies unique shapes and colors based on array indices.Lightweight
โ Minimal code for a visually engaging result, perfect for prototypes or creative UI elements.
โ๏ธ How It Works
HTML โ A simple acts as the container for dynamically generated shapes.
FSCSS โ Uses arrays (list for shapes, colors for backgrounds) and the
@event.shapefunction imported to applyclip-pathstyles dynamically.-
JavaScript โ Creates 10
elements with the shape class, appended to the container. Styling โ Each shape gets a unique
clip-pathand color, displayed inline for a grid-like effect.UI experiments
Loading animations
Interactive backgrounds
๐จ Try It Out
Drop this code into your HTML, ensure the FSCSS library is loaded, and watch colorful shapes come to life!
Itโs great for:
๐ Learn More
Check out the FSCSS for more on @arr, @event and much more.
Share your tweaks or use cases in the comments! ๐
Top comments (0)