Font Size PX to EM with Less CSS

Less is a CSS pre-processor, meaning that it extends the CSS language, adding features that allow variables, mixins, functions and many other techniques that allow you to make CSS that is more maintainable, themable and extendable.

Less made my life simple, to achieve responsive fonts in my development

LESS FILE

// LESS Variable
@base-size = 12;

// CONVERT PX TO EM HERE
.pxToEm(@px){
font-size:(@px/@base-size)+0em;
}

Implementation in CSS
CSS FILE

.h1 {
.pxToEm(22);
}

Output

.h1 {
font-size:1.8333333333333333em;
}
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: