My Journey to a Better CSS Framework
Tags: frontend, webdev, css
Published: 2020-06-20 03:32:15

---
title: My Journey to a Better CSS Framework
published: true
date: 2017-03-06 17:57:55 UTC
tags: frontend,webdevelopment,css
canonical_url: https://medium.com/@shashilo0428/my-journey-to-a-better-css-framework-72bf6dd068bc
---

I told myself I need to start documenting my thoughts and knowledge. I actually have useful things in my brain that could help others. Who knew!? So, I’m going to join the [**52-Week Writing Challenge**](https://writingcooperative.com/the-52-week-writing-challenge-55210b483a21#.6b0sc7j59). My goal is to pour out my knowledge and experience about web development, mostly front-end. Anything from dabbling into a new framework to my daily work experience with projects at [Creed Interactive](http://creedinteractive.com).

#### How it started

How many times have you defaulted to using Bootstrap as your CSS framework because it just works? I’ve done it plenty of times. There are other solutions available, but when you’re working in a team setting, it’s difficult to introduce something new to developers who do not focus on the front-end.

With many viable solutions like [Bootstrap](http://getbootstrap.com/), [Foundation](http://foundation.zurb.com/), [Semantic UI](http://semantic-ui.com/), and more, its reasonable to think there’s no real need to create another framework. But I’m an innovator! I enjoy making things better, faster, more efficient, therefore, I’m going to build my own.

#### My Aha moment

We were conducting an audit on one of our client’s websites because it wasn’t performing well. The obvious issues were: large images, too many Javascript plugins, and large CSS files. You know what I’m talking about if you’ve worked with plenty of WordPress and Drupal websites. After optimizing and resizing the images down to the proper dimensions and minifying both Javascript and CSS files, the performance was much better. But knowing myself, I wanted more improvements. I’m a big fan of lean solutions and removing unneeded extra code. So I ran an audit with Chrome’s developer tools. When I went to look at the “Remove unused CSS rules”, I was surprised that there were over 1800+ rules not used on the homepage. By default, Bootstrap’s CSS file is around 192 kb and 151 kb minified. This doesn’t even include the Javascript file that is 47 kbs minified. Yes, you can remove some features and modify it’s core, but that’s more work on your end. Foundation does an awesome job of providing an interface for you to choose what you want to include/exclude in your base CSS file. But even then, I found myself wanting to something with my knowledge and skills.

My first thought was to create something lean but not too different. My team was familiar with Bootstrap’s class naming convention, so I was going to keep that part. Our team was also experienced in SASS, so building a base SASS system was ideal. I chose to use [Gulp.js](http://gulpjs.com/) over [Grunt](https://gruntjs.com/) and [WebPack](https://webpack.js.org/) for our build system because it was lean and easier to learn. What I wanted to improve was the use of [BEM](http://getbem.com/) (Block Element Model) CSS class naming convention. We also had been using [Includes Media](http://include-media.com/) for our media queries. Lastly, I had to decide how we were going to build our grid system. After discussions with our creative director, we agreed that a 1200px 12 column grid with 10px gutters on both sides would be best for our future designs. At the time I was developing this new CSS framework, Flexbox was just becoming ready to use across all major browsers. In anticipation of this great news, I had a great idea of how to streamline building columns. Why do we have to call out individual column classes that have the same exact column width with the size of each column in it’s own element? That’s because we’re built to do it this way. Well, you don’t have to anymore. Let me save you a couple lines of code from your DOM.

{% gist https://gist.github.com/shashilo/3107b354b53fac01aa28249c66e1b114 %}

In the example above, you can see the common way to call out a row and a few columns to build a footer with side by side links.

{% gist https://gist.github.com/shashilo/66b9ebaec08c5f8b44543c626644be03 %}

Doesn’t that look so much better!? If the columns are going to be the same size, why not control that in the row? It makes for less code and improved efficiency. Yes, it means less control over each column, but in some cases I find that it is a valuable trade-off.

#### The Magic Row

The ability to control the outcome of all columns within a row is amazing to me. Less code, less clutter, and increased efficiency. Let’s take a look at the magic.

{% gist https://gist.github.com/shashilo/f4615d97e75406437aeb821a9168833f %}

Using wildcard selectors for the row class allows you to reference the different screen sizes (xs, sm, md, lg, xl) without adding additional code. Now, all references of the class name of **row-** will use the same styles.

The child combinator is something awesome. It will select elements that are direct descendants. Basically, your first cousin. This eliminates the use of individually assigning each column a class name.

<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fcodepen.io%2Fshashi_lo%2Fembed%2Fpreview%2FoZxKdp%3Fheight%3D600%26amp%3Bslug-hash%3DoZxKdp%26amp%3Bdefault-tabs%3Dcss%2Cresult%26amp%3Bhost%3Dhttp%253A%252F%252Fcodepen.io%26amp%3Bembed-version%3D2&amp;url=https%3A%2F%2Fcodepen.io%2Fshashi_lo%2Fpen%2FoZxKdp%2F&amp;image=https%3A%2F%2Fs3-us-west-2.amazonaws.com%2Fi.cdpn.io%2F851279.oZxKdp.small.e63eb80b-761f-4acf-be9d-fe16b2c0cc4e.png&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=codepen" width="800" height="600" frameborder="0" scrolling="no"><a href="https://medium.com/media/27d002c840b86ff4d890715ac85f0b63/href">https://medium.com/media/27d002c840b86ff4d890715ac85f0b63/href</a></iframe>
#### What’s Next

Everyone wants to do things better and faster. In development, if you can’t improve what you do on a daily basis, you will fall behind and eventually be replaced. Learn how to do what you do with less. As they say, _less is more._

I didn’t intend this to be an article of series, but if I’m going to keep up with my 52 blog articles in 52 weeks, I’m going to stop here and continue adding my thoughts on next week's article.