Column's wise grid designs for device portabil

2019-06-14 19:04发布

问题:

Am gonna try a template which needs to support all devices most of them recommended me to grid framework because using media query by self may cause time but using framework makes fast.Now the thing is i don't about grid and my task is to finish it with foundation framework.! and which is the best way

*)writing media query by own (or)

*)using framework like foundation

and tell me the way and how to use it thanks a lot in advance..!

回答1:

There are two opposite ways to accomplish your task.

Using a non-semantic CSS grid framework

There are a number of CSS grid frameworks. The most popular of them probably are:

  • Twitter Bootstrap;
  • Zurb Foundation;
  • Blueprint.

The advantage of using any of those is that you can prototype your grid very quickly by applying the non-semantic classes to your HTML elements. They also contain a lot of handy decorative styles.

But this approach is considered faulty by many CSS developers. There are a number of problems:

  • By using non-semantic classes you mix structure and presentation, which is fine to make the job done quickly but unacceptable for a serious project.
  • You force your users to download a huge CSS library while you barely use 10% of it on your website (i have to admit that Foundation allows to import different portions of its CSS library separately, and there exits pure grid frameworks like 960gs that don't contain decoration styles at all).
  • You are limited with the sizes and breakpoints provided by the grid system. There's no elegant way to override them. Most of grid systems provide only two responsive styles: small and large, while you may want more (e. g. phone portrait, phone landscape, tablet portrait, tablet landscape, laptop, desktop).

Using the power of SASS and Compass

SASS turns CSS into kinda programming language. You can use variables, functions, methods, you can include libraries of code and execute them with your parameters. The possibilities are almost endlest. You write your styles in SASS and then complile them into vanilla CSS accepted by all browsers.

Compass is a bunch of things under one name:

  • a handy tool to compile SASS efficiently;
  • a huge library of handy SASS styles for all occasions;
  • an ecosystem of extensions that you can install and use in your projects effortlessly.

There exist a number of SASS grid frameworks. They allow you to span your elements semantically. Instead of adding classess to HTML, e. g.:

<aside id="sidebar-left" class="grid-2-of-6 grid-4-of-12">

...you apply CSS to existing selectors, e. g.:

#sidebar-left { @include float-span(2); }

Another advantage is that you're not limited with the defaults. You can alter the number of columns, their width, the breakpoints. You can even have different grids for different portions of the web page! And the most tasty feature is that you can have different number of columns for different screen widths (instead of just making your columns ridiculously narrow).

In my opinion, the best SASS grid system out there is Singularity responsive grid framework. It is extremely powerful and flexible and at the same time it's very smooth and simple to use (once you study it).

For responsive media queries you can use Breakpoint or it's jet-propelled sidekick Breakpoint Slicer. Building a responsive grid with Singularity and Breakpoint Slicer is a pleasure.

SASS and Compass provide other fantastic advantages. For example, you can structure your code very efficiently. It's not a proper place do describe all the ways with which SASS and Compass make your life better. I'll just say that CSS compared to SASS is like a copybook and abacus compared to a spreadsheet processor. I suggest that you google for SASS to learn more.

The downsides of the SASS approach are:

  • You'll have to study it. It takes time.
  • You'll have to keep your styles in SASS. If you want to edit your CSS, you'll have to edit SASS and recompile. That's not much of a hassle and there are ways to automate this or even integrate into the deployment process, but it takes time and effort to adopt them.
  • Your teammates are obliged to use SASS too because any changes in CSS are overwritten during each compilation.
  • Once you start using SASS, you'll never want to code vanilla CSS anymore. That's not a true disadvantage actually. But you should be aware that your life as a frontend developer will never be the same!