<ul class="fancygrid">
<li><a>Item 1</a></li>
<li><a>Item 2</a></li>
<li><a>Item 3</a></li>
<li><a>Item 4</a></li>
<li><a>Item 5</a></li>
<li><a>Item 6</a></li>
</ul>
.fancygrid {
position: relative;
margin: 0;
padding: 0;
display: block;
list-style-type: none;
li {
display: block;
float: left;
margin: 0;
padding: 0;
border: solid 1px #f00;
width: 50px;
height: 50px;
}
}
.fancygrid {
position: relative;
margin: 0;
padding: 0;
display: block;
list-style-type: none;
}
.fancygrid li {
display: block;
float: left;
margin: 0;
padding: 0;
border: solid 1px #f00;
width: 50px;
height: 50px;
}
.fancygrid {
$width: 50px;
$height: 50px;
$hmargin: 10px;
$vmargin: 10px;
position: relative;
margin: 0;
padding: 0;
display: block;
list-style-type: none;
li {
display: block;
float: left;
margin: 0 $hmargin $vmargin 0;
padding: 0;
border: solid 1px #f00;
width: $width;
height: $height;
}
}
@mixin border-radius($radius) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
border-radius: $radius;
}
@mixin rotate($degrees) {
-ms-transform: rotate($degrees);
/* IE 9 */
-webkit-transform: rotate($degrees);
/* Chrome, Safari, Opera */
transform: rotate($degrees);
}
.fancygrid {
$width: 50px;
$height: 50px;
$radius: 5px;
$rotate: 45deg;
$hmargin: 10px;
$vmargin: 10px;
@mixin border-radius($radius) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
border-radius: $radius;
}
@mixin rotate($degrees) {
-ms-transform: rotate($degrees);
-webkit-transform: rotate($degrees);
transform: rotate($degrees);
}
position: relative;
margin: 0;
padding: 0;
display: block;
list-style-type: none;
li {
display: block;
float: left;
margin: 0 $hmargin $vmargin 0;
padding: 0;
border: solid 1px #f00;
width: $width;
height: $height;
@include border-radius($radius);
@include rotate($rotate);
}
}
width: $width * 2;
/* @for */
@for $i from 1 through 3 {
.item-#{$i} { width: 2em * $i; }
}
/* @each */
@each $animal in puma, sea-slug, egret, salamander {
.#{$animal}-icon {
background-image: url('/images/#{$animal}.png');
}
}
/* @while */
$i: 6;
@while $i > 0 {
.item-#{$i} { width: 2em * $i; }
$i: $i - 2;
}
<ul class="fancygrid">
<li class="pos-0-0">
<a href="#1"><span>Item 1</span></a>
</li>
<li class="pos-0-1">
<a href="#1"><span>Item 2</span></a>
</li>
<li class="pos-0-2">
<a href="#1"><span>Item 3</span></a>
</li>
<li class="pos-1-0">
<a href="#1"><span>Item 4</span></a>
</li>
<li class="pos-1-1">
<a href="#1"><span>Item 5</span></a>
</li>
<li class="pos-1-2">
<a href="#1"><span>Item 6</span></a>
</li>
</ul>
.fancygrid {
$textColor: #000;
$width: 50px; // item width
$height: 50px; // item height
$radius: 5px; // corner rounding radius
$rotate: 45deg; // item rotation
$hmargin: 25px; // horizontal margin
$vmargin: 25px; // vertical margin
$top: 0; // initial top position
$left: 0; // initial left position
$rows: 2; // number or rows
$cols: 3; // number of columns
@mixin border-radius($radius) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
border-radius: $radius;
}
@mixin rotate($degrees) {
-ms-transform: rotate($degrees);
-webkit-transform: rotate($degrees);
transform: rotate($degrees);
}
@mixin position($row, $col) {
left: $left + $width/2 + $width*$col + $hmargin*$col;
top: $top + $height/2 + $height*$row + $vmargin*$row;
}
position: relative;
margin: 0;
padding: 0;
display: block;
list-style-type: none;
li {
display: block;
position: absolute;
margin: 0 $hmargin $vmargin 0;
padding: 0;
border: solid 1px #f00;
width: $width;
height: $height;
@include border-radius($radius);
@include rotate($rotate);
/* generate the classes dynamically for all
the available positions. This directly
depends on the $cols and $rows variables
declared above. If you want more rows or columns
just configure it accordingly. */
@for $r from 0 through $rows {
@for $c from 0 through $cols {
&.pos-#{$r}-#{$c} {
@include position($r, $c);
}
}
}
a {
display: block;
text-decoration: none;
display: table-cell;
height: $height;
width: $width;
text-align: center;
vertical-align: middle;
color: $textColor;
span {
display: block;
// rotate the text back the same value
@include rotate(-$rotate);
}
}
}
}
Have a question about something in this article? You can receive help directly from the article author. Sign up for a free trial to get started.
Comments (3)
Commented:
Author
Commented:let me know if after reading the three articles you still feel that something is missing.
It will sure come as a nice subject for a sequel on this series.
Cheers!
Alex
Commented:
Cheers
Marco