forked from csswizardry/fluid-grids
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fluid-grids.php
49 lines (36 loc) · 1.25 KB
/
fluid-grids.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
// How many columns would you like in your grid system?
$totalCols = 16;
// How wide is one column?
$colWidth = 40;
// How wide is one gutter?
$gutterWidth = 20;
// We work these next two out for you, you don’t need to touch them.
$totalWidth = $totalCols * ($colWidth + $gutterWidth);
$fluidGutterWidth = round(($gutterWidth / $totalWidth) * 100, 3);
?>
<pre>
.grid-wrapper{
max-width:<?php echo $totalWidth . 'px;<br>'; ?>
margin-left:-<?php echo $fluidGutterWidth . '%;<br>'; ?>
overflow:hidden;
}
.grid{
float:left;
margin-left:<?php echo $fluidGutterWidth . '%;<br>'; ?>
}
<?php
// Loop through all our possible column widths:
for($i = 1; $i <= $totalCols; $i++){
echo '.grid-' . $i . '{ ';
/**
* The number of columns into the loop, plus the corresponding number
* of gutters, minus one gutter (which is taken up as `margin-left`)
* converted to a percentage (to three decimal places).
*/
$cssWidth = round((((($i * $colWidth) + ($i * $gutterWidth)) - $gutterWidth) / $totalWidth) * 100, 3);
echo 'width:' . $cssWidth . '%;';
echo ' }<br>';
}
?>
</pre>