Why i have grown to hate css libaries

mudakikwa

mudakikwa

Posted on March 2, 2023

Why i have grown to hate css libaries

When it comes to building UI designs, CSS libraries can be a double-edged sword. While they promise to make styling faster and more efficient, they can actually hinder your ability to integrate your finished design into your frontend. As UI designers, we strive to create pixel-perfect designs that are visually stunning and functionally seamless. However, translating these designs from software like Figma or Adobe XD to a production site requires flexibility with spacing and responsiveness across multiple devices.

Unfortunately, using Tailwind to model complex UI designs can quickly become a nightmare. In order to achieve the desired design, users must write a laundry list of CSS classes, leading to a cluttered and difficult-to-maintain codebase. Additionally, debugging your Tailwind CSS can be a frustrating experience, especially when it comes to responsive design. Debugging is crucial to ensuring your UI functions as intended, and any friction in this process can significantly slow down development time.

So, what's the solution? While Tailwind may still have a place in your UI design toolkit, it's best to limit its use to layout design. All other design elements should be handled using Sass files. Sass has a multitude of advanced features that make it a superior choice for styling, including the ability to create functions that scale your fonts according to screen sizes. Using Sass, you can easily define your CSS and make it more modular and easily debuggable. You won't need to dive deep into a sea of classes to figure out why your design isn't rendering correctly.

In conclusion, while CSS libraries have their advantages, it's important to use them judiciously when it comes to complex UI designs. By limiting your use of Tailwind to layouts and utilizing Sass for all other design elements, you can achieve a more flexible and efficient workflow, resulting in stunning and functional UI designs that are sure to impress your users.

Here is an example of modular sass codes that can be used

@function pxToVh($element) {
  @return #{($element/1080) * 100}vh;
}

@function pxToVw($element) {
  @return #{($element/1920) * 100}vw;
}

@function pxToEm($element) {
  @return #{$element/16}em;
}

@mixin scaleFont($font-size) {

  // monitor
  @include mq($xxlg) {
    ont-size: pxToVw($font-size);
  }

  // below 1440px screen
  @include mq($xlg) {
    font-size: pxToEm($font-size);
  }

  @include mq($xls) {
    font-size: $font-size;
  }
}

.text-style-example{
  @include scaleFont(16)
}
Enter fullscreen mode Exit fullscreen mode

with this simple change i won't need to worry about font responsivenes for the entire project and this save me a lot crappy tailwind classes

for guys who are new to sass this just the top of the iceberg of what sass can do here is other sass features

  1. Variables: Sass allows you to define variables for commonly used values such as colors, fonts, and spacing. This makes it easier to update your styles across multiple components without having to change each individual value.
  2. Nesting: Sass allows you to nest selectors within one another, making it easier to read and write your code. This helps you avoid the need to write long, repetitive selectors.
  3. Mixins: Sass mixins allow you to define groups of styles that you can reuse throughout your code. This helps you keep your code DRY (Don't Repeat Yourself) and more maintainable.
  4. Functions: Sass functions allow you to write complex operations that can be reused throughout your code. For example, you can write a function that scales font sizes based on screen size.
  5. Partials: Sass allows you to break your styles into smaller, modular files called partials. This makes it easier to organize your code and keep related styles together.
  6. Import: Sass allows you to import styles from other Sass files, making it easier to reuse code and keep your code organized.
  7. Operators: Sass supports a variety of mathematical operators, including addition, subtraction, multiplication, and division. This makes it easier to perform complex calculations within your styles.
  8. Control Directives: Sass offers control directives such as @if, @for, and @each that allow you to write more advanced logic in your styles. This gives you greater control over how your styles are rendered.

and that guys was my take on tailwind and other css libaries

๐Ÿ’– ๐Ÿ’ช ๐Ÿ™… ๐Ÿšฉ
mudakikwa
mudakikwa

Posted on March 2, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

ยฉ TheLazy.dev

About