Lots of grid improvements, a few sprite tweaks

This commit is contained in:
Mark Perkins
2012-06-22 17:58:57 +01:00
parent c80913f630
commit d8cafeacb5
13 changed files with 431 additions and 62 deletions

View File

@@ -1,5 +1,7 @@
ClearLESS
=========
A reuseable collection of carefully-considered LESS mixins to help speed up development and increase maintainability.
A reuseable collection of carefully-considered LESS mixins to help speed up development and increase maintainability of stylesheets in large projects.

View File

@@ -13,10 +13,57 @@ body {
padding: 20px;
margin: 0;
background: #DDD;
font-size: 10px;
font-family: sans-serif;
min-width: 320px;
}
p,
li {
font-size: 10px;
font-size: 1rem;
}
h1 {
font-size: 15px;
font-size: 1.5rem;
}
h2 {
font-size: 12px;
font-size: 1.2rem;
}
.receptacle {
max-width: 1200px;
margin: 0 auto;
border-bottom: 1px dashed #666;
}
.nav {
padding: 10px 0 10px 10px;
}
.nav li {
margin-bottom: 5px;
list-style: none;
padding: 0;
}
.nav a {
display: inline-block;
position: relative;
padding-left: 16px;
}
.ie6 .nav a,
.ie7 .nav a {
display: inline;
zoom: 1;
}
.nav a:before {
position: absolute;
display: block;
content: ' ';
background-image: url('/examples/sprite.png');
background-repeat: no-repeat;
background-position: -100px -50px;
height: 11px;
width: 6px;
top: 4px;
left: 0;
}
/* ---- grids ---- */
.primary,
@@ -29,8 +76,6 @@ body {
margin-bottom: 2%;
}
.segment {
box-sizing: border-box;
padding: 10px;
margin-bottom: 2%;
overflow: hidden;
}
@@ -88,8 +133,13 @@ body {
.section-3 .segment {
width: 49.2063492063492%;
}
.section-4 .segment {
width: 49.2063492063492%;
}
/* media query example */
@media all and (max-width: 40em) {
.section-3 .segment:nth-child(2n) {
.section-3 .segment:nth-child(2n),
.section-4 .segment:nth-child(2n) {
margin-right: 0;
float: right;
}
@@ -128,13 +178,28 @@ body {
margin-right: 0;
float: right;
}
.section-4 .primary {
width: 11.11111111111111%;
padding-right: 6.349206349206349%;
}
.section-4 .secondary {
width: 11.11111111111111%;
padding-left: 6.349206349206349%;
margin-left: 6.349206349206349%;
}
.section-4 .tertiary {
width: 17.46031746031746%;
margin-left: 6.349206349206349%;
}
.section-4 .quaternary {
width: 17.46031746031746%;
padding-left: 6.349206349206349%;
margin-right: 6.349206349206349%;
}
}
/* Nested Grids */
.section-parent .segment {
display: inline;
float: left;
width: 49.2063492063492%;
margin-right: 1.5873015873015872%;
}
.section-parent > .secondary {
background-color: transparent;
@@ -143,16 +208,19 @@ body {
float: right;
}
.section-nested .segment {
display: inline;
float: left;
width: 22.58064516129032%;
margin-right: 3.225806451612903%;
background: #999;
}
.section-nested .segment:nth-child(4n) {
.floated .section-nested .segment > .secondary,
.floated .section-parent .segment:nth-child(4n) {
margin-right: 0;
float: right;
}
.inline .section-nested .segment > .secondary,
.inline .section-parent .segment:nth-child(4n) {
margin-right: 0;
}
/* Sprites & Icons */
.more {
display: inline-block;
@@ -176,13 +244,19 @@ body {
top: 4px;
right: 0;
}
.nav li {
.icon-nav a {
display: inline-block;
padding-top: 10px;
padding-bottom: 10px;
position: relative;
padding-left: 38px;
}
.nav li:before {
.ie6 .icon-nav a,
.ie7 .icon-nav a {
display: inline;
zoom: 1;
}
.icon-nav a:before {
position: absolute;
display: block;
content: ' ';
@@ -194,13 +268,28 @@ body {
top: 2px;
left: 0;
}
.nav li.rockets:before {
background-position: 0px -50px;
.icon-nav .robots a:before {
background-position: 0px 0px;
}
.nav li.runners:before {
.icon-nav .robots a:hover:before {
background-position: -50px 0px;
}
.nav li.ghosts:before {
.icon-nav .rockets a:before {
background-position: 0px -50px;
}
.icon-nav .rockets a:hover:before {
background-position: -50px -50px;
}
.icon-nav .runners a:before {
background-position: 0px -100px;
}
.icon-nav .runners a:hover:before {
background-position: -50px -100px;
}
.icon-nav .ghosts a:before {
background-position: 0px -150px;
}
.icon-nav .ghosts a:hover:before {
background-position: -50px -150px;
}
/* Other Helpers */

View File

@@ -1,14 +1,18 @@
@import "../mixins/all";
// Default settings override
@sprite-image: url('/examples/sprite.png');
@using-modernizr: false;
@using-ieclasses: true;
@column-width: 60px;
@gutter-width: 20px;
@column-width: 60;
@gutter-width: 20;
@base-font-size: 10;
// Project settings
@mobile-width: 40em;
/* ---- setup ---- */
@@ -17,11 +21,40 @@ body {
padding: 20px;
margin: 0;
background: #DDD;
font-size: ~"@{base-font-size}px";
font-family: sans-serif;
min-width: 320px;
}
p, li {
.font-size-rems(1);
}
h1 {
.font-size-rems(1.5);
}
h2 {
.font-size-rems(1.2);
}
.receptacle {
max-width: 1200px;
margin: 0 auto;
border-bottom: 1px dashed #666;
}
.nav {
padding: 10px 0 10px 10px;
li {
margin-bottom: 5px;
list-style: none;
padding: 0;
}
a {
.inline-block();
.icon(2, 1, 6px, 11px, 10px, 0, 4px);
}
}
/* ---- grids ---- */
@@ -38,8 +71,6 @@ body {
}
.segment {
box-sizing: border-box;
padding: 10px;
margin-bottom: 2%;
overflow: hidden;
}
@@ -87,8 +118,18 @@ body {
}
}
.section-4 {
.segment {
.span(8);
}
}
/* media query example */
@media all and ( max-width: @mobile-width ) {
.section-3 .segment:nth-child(2n) {
.section-3 .segment:nth-child(2n),
.section-4 .segment:nth-child(2n) {
.end-column();
}
}
@@ -110,7 +151,7 @@ body {
}
.secondary {
.span(6);
.end-column()
.end-column();
}
}
@@ -129,17 +170,40 @@ body {
}
.quaternary {
.span(3);
.end-column()
.end-column();
}
}
.section-4 {
.primary {
.span(2);
.post-pad(1);
}
.secondary {
.span(2);
.pre-pad(1);
.pre-push(1);
}
.tertiary {
.span(3);
.pre-push(1);
}
.quaternary {
.span(3);
.pre-pad(1);
.post-push-end(1);
}
}
}
/* Nested Grids */
.section-parent {
.segment {
.column(8);
.span(8);
}
> .secondary {
background-color: transparent;
@@ -150,37 +214,64 @@ body {
.section-nested {
.segment {
.column(2,8);
.span(2,8);
background: #999;
}
.segment:nth-child(4n) {
}
.floated {
.section-nested .segment > .secondary,
.section-parent .segment:nth-child(4n) {
.end-column();
}
}
.inline {
.section-nested .segment > .secondary,
.section-parent .segment:nth-child(4n) {
.inline-end-column();
}
}
/* Sprites & Icons */
.more {
.inline-block();
.icon-right(2, 1, 6px, 11px, 10px, 0, 4px);
}
.nav li {
padding-top: 10px;
padding-bottom: 10px;
.icon-left(0, 0, 28px, 28px, 10px, 0, 2px);
.right-icon(2, 1, 6px, 11px, 10px, 0, 4px);
}
.nav li.rockets {
.icon-left-pos(0,1);
}
.nav li.runners {
.icon-left-pos(1,0);
}
.nav li.ghosts {
.icon-left-pos(1,1);
.icon-nav {
a {
.inline-block();
padding-top: 10px;
padding-bottom: 10px;
.icon(0, 0, 28px, 28px, 10px, 0, 2px);
}
.robots a {
.icon-pos(0,0);
&:hover {
.icon-pos(1,0);
}
}
.rockets a {
.icon-pos(0,1);
&:hover {
.icon-pos(1,1);
}
}
.runners a {
.icon-pos(0,2);
&:hover {
.icon-pos(1,2);
}
}
.ghosts a {
.icon-pos(0,3);
&:hover {
.icon-pos(1,3);
}
}
}
/* Other Helpers */

View File

@@ -2,7 +2,8 @@
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="shortcut icon" href="http://clearleft.com/favicon.ico" type="image/x-icon" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="http://clearleft.com/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="/_compiled/example.css" type="text/css">
@@ -72,6 +73,26 @@
</div>
<div class="section-4 section">
<div class="primary segment">
<p>primary</p>
</div>
<div class="secondary segment">
<p>secondary</p>
</div>
<div class="tertiary segment">
<p>tertiary</p>
</div>
<div class="quaternary segment">
<p>quaternary</p>
</div>
</div>
</div>
<div class="receptacle inline">
@@ -130,6 +151,27 @@
</div>
<div class="section-4 section">
<div class="primary segment">
<p>primary</p>
</div>
<div class="secondary segment">
<p>secondary</p>
</div>
<div class="tertiary segment">
<p>tertiary</p>
</div>
<div class="quaternary segment">
<p>quaternary</p>
</div>
</div>
</div>
</body>

View File

@@ -2,6 +2,7 @@
<html lang="en" class="generatedcontent">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="http://clearleft.com/favicon.ico" type="image/x-icon" />
<link rel="stylesheet/less" type="text/css" href="example.less">
@@ -11,12 +12,20 @@
</head>
<body>
<h1>ClearLESS Examples</h1>
<div class="receptacle header">
<h1>ClearLESS Examples</h1>
</div>
<div class="receptacle">
<ul>
<li><a href="grids.html">Grids</a></li>
<li><a href="sprites.html">Sprites &amp; Icons</a></li>
</ul>
<ul class="nav">
<li><a href="sprites.html">Sprites &amp; Icons</a></li>
<li><a href="grids.html">Grids</a></li>
<li><a href="nested-grids.html">Nested Grids</a></li>
<li><a href="other.html">Other</a></li>
</ul>
</div>
</body>
</html>

View File

@@ -2,6 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="http://clearleft.com/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="/_compiled/example.css" type="text/css">
@@ -75,5 +76,65 @@
</div>
<div class="receptacle inline">
<h2>Inline</h2>
<div class="section-1 section">
<div class="primary segment">
<p>primary</p>
</div>
<div class="secondary segment">
<p>secondary</p>
</div>
<div class="tertiary segment">
<p>tertiary</p>
</div>
<div class="quaternary segment">
<p>quaternary</p>
</div>
</div>
<div class="section-parent section">
<div class="primary segment">
<p>primary</p>
</div>
<div class="secondary segment">
<div class="section-nested section">
<div class="primary segment">
<p>primary</p>
</div>
<div class="secondary segment">
<p>secondary</p>
</div>
<div class="tertiary segment">
<p>tertiary</p>
</div>
<div class="quaternary segment">
<p>quaternary</p>
</div>
</div>
</div>
</div>
</div>
</body>
</html>

28
examples/other.html Normal file
View File

@@ -0,0 +1,28 @@
<!DOCTYPE html>
<html lang="en" class="generatedcontent">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="http://clearleft.com/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="/_compiled/example.css" type="text/css">
<title>ClearLESS Examples</title>
</head>
<body>
<div class="receptacle header">
<h1>Other Examples</h1>
</div>
<div class="receptacle">
</div>
</body>
</html>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 3.6 KiB

View File

@@ -2,6 +2,7 @@
<html lang="en" class="generatedcontent">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="http://clearleft.com/favicon.ico" type="image/x-icon" />
<link rel="stylesheet" href="/_compiled/example.css" type="text/css">
@@ -10,13 +11,21 @@
</head>
<body>
<h1>Sprites &amp; Icons</h1>
<div class="receptacle header">
<h1>Sprites &amp; Icons</h1>
</div>
<div class="receptacle">
<p><a href="#" class="more">Read more</a></p>
<ul class="nav">
</div>
<div class="receptacle">
<ul class="icon-nav">
<li class="robots"><a href="#">Robots</a></li>
<li class="rockets"><a href="#">Rockets</a></li>
<li class="runners"><a href="#">Runners</a></li>

View File

@@ -21,6 +21,10 @@
float: right;
}
.inline-end-column() {
margin-right: 0;
}
.span( @span ) {
.column-width(@span, @total-columns);
@@ -88,6 +92,33 @@
}
.pre-pad( @span ) {
@calc-column-width: 100%*((((@gutter-width+@column-width)*@span)) / @grid-width);
padding-left: @calc-column-width;
}
.post-pad( @span ) {
@calc-column-width: 100%*((((@gutter-width+@column-width)*@span)) / @grid-width);
padding-right: @calc-column-width;
}
.pre-push( @span ) {
@calc-column-width: 100%*((((@gutter-width+@column-width)*@span)) / @grid-width);
margin-left: @calc-column-width;
}
.post-push( @span ) {
@calc-column-width: 100%*((((@gutter-width+@column-width)*@span)+@gutter-width) / @grid-width);
margin-right: @calc-column-width;
}
.post-push-end( @span ) {
@calc-column-width: 100%*((((@gutter-width+@column-width)*@span)) / @grid-width);
margin-right: @calc-column-width;
}
.column-width(@span, @total-columns:@total-columns) {
@calc-column-width: 100%*((((@gutter-width+@column-width)*@span)-@gutter-width) / @grid-width);
width: @calc-column-width;

View File

@@ -13,7 +13,14 @@
}
}
.font-size-ems(@target-px-size, @context-px-size:@base-font-size-px) {
.font-size-rems(@px-size, @context-px-size:@base-font-size){
@rem-value: @px-size;
@px-value: (@px-size * @context-px-size);
font-size: ~"@{px-value}px";
font-size: ~"@{rem-value}rem";
}
.font-size-ems(@target-px-size, @context-px-size:@base-font-size) {
font-size: (@target-px-size / @context-px-size) * 1em;
}

View File

@@ -9,7 +9,7 @@
@using-ieclasses: true; // whether or not the markup has html5-boilerplate style IE classes in it or not
@using-modernizr: false; // whether or not modernizer feature-detection classes are being used
@base-font-size-px: 16; // base pixel font size. Used as a default for px-em conversions
@base-font-size: 16; // base pixel font size. Used as a default for px-em conversions
// Sprites --------------------------------

View File

@@ -32,7 +32,7 @@
// These can only be used on block or inline-block elements.
// ==============================================
.icon-left(@x, @y, @width, @height, @pad:10, @nudge-left:0, @nudge-top:0, @sprite-image:@sprite-image, @sprite-grid:@sprite-grid) when (@using-modernizr) {
.icon(@x, @y, @width, @height, @pad:10, @nudge-left:0, @nudge-top:0, @sprite-image:@sprite-image, @sprite-grid:@sprite-grid) when (@using-modernizr) {
.generatedcontent & {
position: relative;
padding-left: (@width + @pad) * 1px;
@@ -44,7 +44,7 @@
}
}
.icon-left(@x, @y, @width, @height, @pad:10, @nudge-left:0, @nudge-top:0, @sprite-image:@sprite-image, @sprite-grid:@sprite-grid) when (@using-modernizr = false) {
.icon(@x, @y, @width, @height, @pad:10, @nudge-left:0, @nudge-top:0, @sprite-image:@sprite-image, @sprite-grid:@sprite-grid) when (@using-modernizr = false) {
position: relative;
padding-left: (@width + @pad) * 1px;
&:before {
@@ -54,7 +54,7 @@
}
}
.icon-right(@x, @y, @width, @height, @pad:10, @nudge-right:0, @nudge-top:0, @sprite-image:@sprite-image, @sprite-grid:@sprite-grid) when (@using-modernizr) {
.right-icon(@x, @y, @width, @height, @pad:10, @nudge-right:0, @nudge-top:0, @sprite-image:@sprite-image, @sprite-grid:@sprite-grid) when (@using-modernizr) {
.generatedcontent & {
padding-right: (@width + @pad) * 1px;
position: relative;
@@ -66,7 +66,7 @@
}
}
.icon-right(@x, @y, @width, @height, @pad:10, @nudge-right:0, @nudge-top:0, @sprite-image:@sprite-image, @sprite-grid:@sprite-grid) when (@using-modernizr = false) {
.right-icon(@x, @y, @width, @height, @pad:10, @nudge-right:0, @nudge-top:0, @sprite-image:@sprite-image, @sprite-grid:@sprite-grid) when (@using-modernizr = false) {
position: relative;
padding-right: (@width + @pad) * 1px;
&:before {
@@ -76,7 +76,7 @@
}
}
.icon-left-pos(@x, @y, @nudge-left:0, @nudge-top:0, @sprite-grid:@sprite-grid) when (@using-modernizr) {
.icon-pos(@x, @y, @nudge-left:0, @nudge-top:0, @sprite-grid:@sprite-grid) when (@using-modernizr) {
.generatedcontent &:before {
.sprite-pos(@x, @y, @sprite-grid);
.nudge-l(@nudge-left);
@@ -84,7 +84,7 @@
}
}
.icon-left-pos(@x, @y, @nudge-left:0, @nudge-top:0, @sprite-grid:@sprite-grid) {
.icon-pos(@x, @y, @nudge-left:0, @nudge-top:0, @sprite-grid:@sprite-grid) {
&:before {
.sprite-pos(@x, @y, @sprite-grid);
.nudge-l(@nudge-left);
@@ -92,7 +92,7 @@
}
}
.icon-right-pos(@x, @y, @nudge-right:0, @nudge-top:0, @sprite-grid:@sprite-grid) when (@using-modernizr) {
.right-icon-pos(@x, @y, @nudge-right:0, @nudge-top:0, @sprite-grid:@sprite-grid) when (@using-modernizr) {
.generatedcontent &:before {
.sprite-pos(@x, @y, @sprite-grid);
.nudge-r(@nudge-right);
@@ -100,7 +100,7 @@
}
}
.icon-right-pos(@x, @y, @nudge-right:0, @nudge-top:0, @sprite-grid:@sprite-grid) {
.right-icon-pos(@x, @y, @nudge-right:0, @nudge-top:0, @sprite-grid:@sprite-grid) {
&:before {
.sprite-pos(@x, @y, @sprite-grid);
.nudge-r(@nudge-right);