Composition in web design, or what Photoshop tutorials are silent about
Surely, you often have to visit sites that, at first glance, seem to be like nothing - both the pictures are beautiful and the text is folding, however, they lack…

Continue reading →

How to create a selling portfolio of web designer?
You can become a web design master in many different ways. For example, there are people who achieve significant results in this activity through a simple internship in the studio.…

Continue reading →

The Importance of Visual Context in Web Design
From the author: According to the results of a popular study by the University of Missouri Science and Technology, visitors form an opinion about your business site in less than…

Continue reading →

Advanced CSS: Using Sass Maps for UI Components

Sass is a great and very popular CSS preprocessor. If you are not familiar with it, take a look at these lessons.

Associative arrays (Maps) are an extremely underrated feature of Sass. They help automate the creation of user interface elements and improve the architecture of the entire application. Associative arrays will come in handy when you need a set of modifier classes for user interface elements.

A modifier is a class that modifies the style of a block depending on the context. A block is a universal parent class that can be used on its own.

BEM (Block Element Modifier)

I have summarized several code snippets and patterns that I often use. Although, of course, you must be able to apply this technique to other elements of the interface.

Sass Associative Array Syntax
Sass (Scss)
$ map: (
key-1: value-1,
key-2: value-2,
key-3: value-3
);
You can get the value by the key like this:

Sass (Scss)
map-get ($ map, key)
Customization
You probably have a Sass file in which you declare all the variables (something like _variables.scss or _base.scss). If not, you must create it. Here we will describe our map.

After several attempts and errors, I realized that the best way to configure associative arrays is to first declare the variables and then create a Map with these variables. This method allows you to use simple variables in the code (for example, $ color-robin) instead of getting the value using map-get (for example, map-get ($ ui-colors, primary)).

Sass (Scss)
// UI Colors
$ color-robin: # 8FCCCC;
$ color-vista: # 79D1AD;
$ color-mandy: # e67478;
$ color-apricot: # ed8864;
$ color-eastside: # 9279c3;

// UI Colors Map
$ ui-colors: (
default: $ color-robin,
success: $ color-vista,
error: $ color-mandy,
warning: $ color-apricot,
info: $ color-eastside
);
I usually declare 4 maps:

Theme colors (corporate identity colors)
Colors of interface elements (colors for errors, tooltips, buttons)
Grayscale (colors for text, shadows, backgrounds)
Corporate colors (used, for example, for social network icons)
The same template will be used for typography. You can first declare individual variables for fonts, and then put them in an array.

What variables should be used in an associative array? The variables that you will use in mixins to create modifier classes. Except for the obvious – color selection – associative arrays can be used for typography, icons or images. In the following example, I will show how to create different classes for buttons using the UI Colors color map.

Buttons
I use the each directive, which loops through the $ ui-colors array and creates a modifier class for the .button base class. We get modifiers to style buttons like ‘error’ or ‘success’.

Sass (Scss)
.button {
// common styles for all buttons
// …
// generates modifier classes
& – # {$ theme} {
background-color: $ color;
color: transparentize ($ white, .2);
}
& – # {$ theme}: hover,
& – # {$ theme}: focus {
background-color: shade ($ color, 20%);
color: $ white;
}
}
// Usage:
// .button .button – default
// .button .button – success
// .button .button – error
// .button .button – warning
// .button .button – info
This approach eliminates the need for code duplication. And also, if you want to change some color in the color scheme or add new colors – all interface elements will be updated automatically.

A similar pattern can be used for flags, links, and other elements that use modifiers.

Social Networking Icons
I used the same template as in the previous example, but this time I added social network icons. The code below creates a social-media-icon block class and modifiers for various icons.

Sass (Scss)
// Colors
$ color-facebook: # 3B5998;
$ color-twitter: # 55ACEE;
$ color-pinterest: # CC2127;
$ color-youtube: # E52D27;

$ social-media-icons: (
facebook: $ icon-facebook,
twitter: $ icon-twitter,
pinterest: $ icon-pinterest,
youtube: $ icon-youtube
)

// Icons
$ icon-facebook: url (‘assets / facebook.png’);
$ icon-twitter: url (‘assets / twitter.png’);
$ icon-pinterest: url (‘assets / pinterest.png’);
$ icon-youtube: url (‘assets / youtube.png’);

$ social-media-colors: (
facebook: $ color-facebook,
twitter: $ color-twitter,
pinterest: $ color-pinterest,
youtube: $ color-youtube
)
.social-media-icon {
border-radius: 50%;
padding: .5rem;
text-align: center;
background-size: cover;
background-repeat: no-repeat;
@each $ theme, $ color in $ social-media-colors {
& – # {$ theme} {
background-color: $ color;
}
}
@each $ theme, $ icon in $ social-media-icons {
& – # {$ theme} {
background-attachment: $ icon;
}
}
}
// Usage:
// .social-media-icon .social-media-icon – facebook
// .social-media-icon .social-media-icon – twitter

Best One-Page Website Designs (Landing Page)
An illiterate landing page to which new users are directed can lead to the depreciation of the entire advertising company. If you want to build a successful and carefree career…

...

How to create a selling portfolio of web designer?
You can become a web design master in many different ways. For example, there are people who achieve significant results in this activity through a simple internship in the studio.…

...

Website framework, or modular grid in web design
What is a modular grid? I will explain with an example familiar to you. Open any paper book. You see, the text passing through the entire width of the page,…

...

Web design basics. Analysis of the main blocks on the site
A true web design master 2.0 should be able to surprise people with innovative thinking and a creative approach to solving tasks. However, this does not mean that you need…

...