Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Compass/sass for percentage width responsive layouts?

I am trying to use Sass (and Compass) to simplify the creation of a percentage-width layout.

Using the formula from A List Apart of target/context=result, where the context is 980px and the design width is 640px, I tried doing a rule of

#leftcol {
width: ((640/980)*100%);
}

Which compiles to

#leftcol {
  width: 65.306%;
}

Is there an easier way than to do that without typing that over and over?

like image 445
Steve Avatar asked Dec 15 '22 23:12

Steve


1 Answers

No mixin needed. Sass has a built-in percentage function that accepts a variety of units.

width: percentage(640 / 980)
width: percentage(640px / 980px)

both result in:

width: 65.30612%
like image 176
philoye Avatar answered Dec 28 '22 08:12

philoye