LESS: DRY Stylesheets with Mixins and Variables
It’s 2010, and we’re all tired of copy-pasting hex codes and repeating the same vendor prefixes across our CSS files. If you're building a "Web 2.0" site with gradients and rounded corners, your CSS is probably a nightmare to maintain.
LESS is here to save us. It extends CSS with dynamic behavior.
Variables
Stop searching and replacing hex codes. Define them once.
@primary-color: #4D926F;
@border-radius: 5px;
header {
color: @primary-color;
}
.button {
background-color: @primary-color;
border-radius: @border-radius;
}
Mixins
Mixins allow you to embed all the properties of a class into another class. This is perfect for those repetitive CSS3 properties.
.rounded-corners(@radius: 5px) {
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
border-radius: @radius;
}
#header {
.rounded-corners;
}
#footer {
.rounded-corners(10px);
}
Nesting
Instead of writing long selectors, you can nest them. It matches your HTML structure and makes the code much cleaner.
#header {
h1 {
font-size: 26px;
font-weight: bold;
}
p {
font-size: 12px;
a {
text-decoration: none;
&:hover { border-width: 1px }
}
}
}
In 2010, LESS is the leading tool for anyone who wants to write CSS like a programmer. It’s making the web look better, one variable at a time.
Aunimeda builds modern web frontends - from single-page applications to complex multi-locale sites.
Contact us to discuss your frontend project. See also: Web Development, Corporate Website Development