Created
August 13, 2009 17:10
-
-
Save dallas/167305 to your computer and use it in GitHub Desktop.
thoughts on CSS columnar grids in TextMate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Need to make a columnar CSS layout (for a 960-grid, say)? | |
Have a fixed width base to work off of (like 960 pixels)? | |
Want it in all kinds of sizes (2,3,4,5,6,8,10 & 12, say)? | |
Then this is the snippet for you! | |
In TextMate, you can just select all | |
of the following lines and press: | |
Ctrl + Shift + E (evaluate as ruby). | |
This snippet is based on a 960px base, | |
with 10px of padding on each column, | |
and is set up for up to 12 columns of | |
control. Columns that would produce | |
decimal-width columns have been omitted. | |
.column1of1 would be full width, so it | |
is not included here. | |
*/ | |
w = 960 | |
[2,3,4,5,6,8,10,12].each do |n| | |
col_w = (w / n.to_f).floor # width of each column | |
(1..(n - 1)).each do |i| | |
puts "\n/* #{n}-columns */" if i == 1 | |
x = (col_w * i) - 20 # this column's width | |
y = x + 20 # width of this column + padding | |
puts ".column#{i}of#{n}#{' ' if i < 10}#{' ' if n < 10} { width:#{' ' if x < 100}#{x}px; /* #{' ' if y < 100}#{y}px with padding */ }\n" | |
end | |
end | |
/* Sample output: */ | |
/* 2-columns */ | |
.column1of2 { width:460px; /* 480px with padding */ } | |
/* 3-columns */ | |
.column1of3 { width:300px; /* 320px with padding */ } | |
.column2of3 { width:620px; /* 640px with padding */ } | |
/* 4-columns */ | |
.column1of4 { width:220px; /* 240px with padding */ } | |
.column2of4 { width:460px; /* 480px with padding */ } | |
.column3of4 { width:700px; /* 720px with padding */ } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment