LESS basics. Code examples open

LESS basics. Code examples

Variables:

@primary: red;
@main: blue;
@width: 100px;

Use thr variable:

div {
	margin: 40px;
	width: @width;
}

The path to our files can be stored in variables:

@img: "../img/";

Let’s use it:

.div {
	background: url("@{img}bg.jpg") center no-repeat;
}

Import:

@import "variables"

Nested elements:

div {
	margin: 40px;
	width: @width;
	&--classname {
		background:red;
	}
	&--another-class-name {
		
	}
}

Multi-level nesting is allowed:

div {
	margin: 40px;
	width: @width;
	&:hover,
	&:focus {
		text-decoration:none;
	}

}

Example of function:

div {
	color: darken(red, 20)
}

When 2 buttons are next to each other, you can add an indent between them:

.btn {
   &+& {
   	margin-right: 1rem;
   }
}

You can apply directly from the class to:

.btn {
	.disabled & {
	color: silver;
	}
}

Mixins:

.btn(@bg) {
	background-color: @bg;

	&hover,
	&focus {
		background-color: @bg;
	}	
}

Use the mixins:

div {
	color: darken(red, 20);
	.btn(red);
}

Conditions:

& when(lightness(@bg) > 50) {
	color: @black;
}

Media queries can be written directly in the selector:

.div {
	width:500px;
	@media (min-width:501px) {
		background: red;
	}
}

~ – leaves quotes in variables

Basic grid on LESS. Code example open
Basic grid on LESS. Code example
November 23, 2022
srgey@gmail.com
0

More

Leave a Reply

Your email address will not be published. Required fields are marked *

How many?: 22 + 22

lil-code© | 2022 - 2024
Go Top
Authorization
*
*
Registration
*
*
*
*
Password generation