Bootcamp

From idea to product, one lesson at a time. To submit your story: https://tinyurl.com/bootspub1

Follow publication

Member-only story

A Sass Mixin to Build Your Own CSS Framework à la Tailwind

Tristan Wolff
Bootcamp
Published in
4 min readJul 15, 2023

--

Photo by Mike Dorner on Unsplash

In a recent project I built from scratch, I was intrigued by the idea of experimenting with chunking my app to optimize its performance when deployed on the blockchain. One of my primary goals was to minimize the number of CSS files included in the project. As I explored this further, I had the idea of using components with a class-based approach similar to Tailwind CSS. However, I steered clear of relying on any external frameworks, as I’ve always been cautious about adding unnecessary dependencies if they aren’t required. I also believed that this experiment could provide greater flexibility in the long run.

In a nutshell, I ended up creating a Sass mixin for building my own class-based framework. In this blog post, I’m excited to share it with you.

The project we built together with my colleagues is called Oisy. It’s an open-source Ethereum wallet hosted on the Internet Computer.

Overview

The idea behind the mixin is to eliminate code duplication while enabling the generation of classes that can be used to create responsive components. For instance, consider the following code snippet:

<div class="flex justify-center gap-1 mt-4">
<span class="text-blue">Hello</span>
<span class="text-cyclamen font-bold">World</span>
</div>

This code would render a web page featuring a div container with a centered flex layout and a top margin. Inside this container, there are two inline span elements, each assigned specific colors, with one of them set to bold text.

While I could have simply declared these classes globally, my objective was to generate them using a Sass utility for all my styling needs.

Gotcha

This solution exceeded my expectation when I first began to code it but, it’s essential to note that it’s not as advanced as dedicated CSS frameworks like Tailwind. Before we proceed further, it’s important to be aware of the following two limitations:

  1. Responsivity in this solution is limited to the usage one breakpoint

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Bootcamp
Bootcamp

Published in Bootcamp

From idea to product, one lesson at a time. To submit your story: https://tinyurl.com/bootspub1

Tristan Wolff
Tristan Wolff

Responses (2)

Write a response