Nadi Dikun    Interface Mechanics
   About    Contact   

Custom responsive grid-based CSS framework

These days I’ve been re-developing my online portfolio, so it is mobile friendly and more interactive. This work hasn’t been finished yet, so here is a sneak peek:

Nadi's portfolio sneak peak

As you can see, it has a pretty uncommon timeline-based structure, which divides the screen into two equal 50% width columns. Each of these columns contains separate projects and events, that have their own <sections> with different data inside. The main question for me was - how to properly structure all of them to build a sustainable DOM structure that would be responsive and would allow me to load all my projects using JSON in the future?

Quite an interesting challenge, right? :)

The first part of the answer is pretty straightforward - to have a structured HTML, you need to build a grid-based layout. Great! It was easy, right? But hey, look at my design! How many columns do you think I need? Also, how would you position the project in both sides of the timeline, if all of them are kept in one JSON file (read: in one Javascript object) and will be loaded one-by-one?

I’ve came up with the structure, where each project is being handled as a .row, which takes full width of the screen and being positioned by CSS rules to the appropriate side, depending on the type of property in the corresponding JSON object.

As for the grid system, I started with the most narrow element (the one with dates), which needed to be about 1/24 of the width to keep the correct visual proportions. However, I decided to use a 12-column grid. Why? Well, I “nested” it.

Each project ( .row ) contains two 50%-width columns ( .col-6 ). Each of these columns would have 12 columns inside (which gives us 24 columns in total to serve the most narrow element). It works great, since the grid system is based on percentages.

Now to the grid itself. The most popular grid-based system is Bootstrap. However, it has too many build-in features that I’m not going to use for a one-page portfolio. So to keep my web page as lightweight as possible, I coded my own tiny 12-column grid system.

It’s pretty easy to code your own grid-based CSS framework, once you know the responsive break points that will be needed for your design. In my case I’ve included the following break points:

  • max-width: 670px - mainly for phones
  • max-width: 768px - mainly for tablets
  • max-width: 1199px - mainly for laptops

Check the code below:

html * {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

*, *:after, *:before { -webkit-box-sizing: border-box; -moz-box-sizing: border-box; -ms-box-sizing: border-box; box-sizing: border-box; }

.row { width: 100%; }

/* || Nice clearfix for grouped elements || / .group:after { visibility: hidden; display: block; content: ""; clear: both; height: 0; } * html .group { zoom: 1; } / IE6 / *:first-child+html .group { zoom: 1; } / IE7 / / clefix ends */

.col-1 { width: 8.33%; } .col-2 { width: 16.66%; } .col-3 { width: 25%; } .col-4 { width: 33.33%; } .col-5 { width: 41.66%; } .col-6 { width: 50%; } .col-7 { width: 58.34%; } .col-8 { width: 66.67%; } .col-9 { width: 75%; } .col-10 { width: 83.34%; } .col-11 { width: 91.67% } .col-12 { width: 100%; }

@media (min-width: 769px) and (max-width: 1199px) { .col-sm-1 { width: 8.33%; } .col-sm-2 { width: 16.66%; } .col-sm-3 { width: 25%; } .col-sm-4 { width: 33.33%; } .col-sm-5 { width: 41.66%; } .col-sm-6 { width: 50%; } .col-sm-7 { width: 58.34%; } .col-sm-8 { width: 66.67%; } .col-sm-9 { width: 75%; } .col-sm-10 { width: 83.34%; } .col-sm-11 { width: 91.67% } .col-sm-12 { width: 100%; } }

@media (min-width: 671px) and (max-width: 768px) { .col-tab-1 { width: 8.33%; } .col-tab-2 { width: 16.66%; } .col-tab-3 { width: 25%; } .col-tab-4 { width: 33.33%; } .col-tab-5 { width: 41.66%; } .col-tab-6 { width: 50%; } .col-tab-7 { width: 58.34%; } .col-tab-8 { width: 66.67%; } .col-tab-9 { width: 75%; } .col-tab-10 { width: 83.34%; } .col-tab-11 { width: 91.67% } .col-tab-12 { width: 100%; } }

@media (max-width: 670px) { .col-ph-1 { width: 8.33%; } .col-ph-2 { width: 16.66%; } .col-ph-3 { width: 25%; } .col-ph-4 { width: 33.33%; } .col-ph-5 { width: 41.66%; } .col-ph-6 { width: 50%; } .col-ph-7 { width: 58.34%; } .col-ph-8 { width: 66.67%; } .col-ph-9 { width: 75%; } .col-ph-10 { width: 83.34%; } .col-ph-11 { width: 91.67% } .col-ph-12 { width: 100%; } }

comments powered by Disqus