CSS

The current CS-Cart styles are based on native CSS features. Modern CSS provides great opportunities, e.g. variables and calc math operations.

LESS

LESS is the CSS preprocessor that enlarges its possibilities. Learn more about LESS at the official LESS website.

Important

LESS styles are marked as deprecated, and they will be no longer supported in future. LESS opportunities are no longer used in writing new styles, e.g. for Nova theme.

At the moment, LESS styles are supported to maintain backward compatibility.

Recommendations for LESS

  • Use LESS functionality only in special cases:

    • styles/data/style_name.less—using LESS functions and assigning them to LESS variables;

    • css/tygh/less_functions.less—assigning previously obtained LESS variables to CSS variables for further use of LESS in other cases. You can also use mixins here.

      Example

      // styles/data/Nova_theme.less
      @menu: #fff;
      @menu_hover: darken(@menu, 5%);
      
      // css/tygh/less_functions.less
      :root {
          --cs-menu: @menu;
          --cs-menu-hover: @menu_hover;
      }
      
      // css/blocks/topmenu_dropdown.less
      .ty-menu__items {
      background: var(--cs-menu);
      }
      
      .ty-menu__item-active .ty-menu__item-link {
      background: var(--cs-menu-hover);
      }
      
  • Consider the following usage examples:

    • design/themes/nova_theme/styles/data/Nova_theme.less—using LESS functions
    • design/themes/nova_theme/css/tygh/less_functions.less—assigning to CSS variables
    • design/themes/nova_theme/css/blocks/topmenu_dropdown.less—using CSS variables

Important

  • New CSS styles in CS-Cart are written in .less files to maintain backward compatibility.
  • Math operations in LESS styles have a different behaviour if compared with CSS styles. Learn more in Operations section.

In the next section we describe how to switch from LESS to native CSS.

Variables

This functionality allows creating variables and using them to define property values in several places.

Example:

@price: #343434;

LESS variables in CS-Cart are related to the Styles concept (see the Styles and Theme Editor section further in this guide).

In the design/themes/THEME_NAME/styles/data directory of your CS-Cart installation there are the .less files that contain the LESS variables related to the Theme Editor (where THEME_NAME is the name of your theme).

These values can be edited in a file or received with the Theme Editor after saving a style.

Values of the variables in the .less file of this directory can be edited only in the given file. For example, if the @price variable is defined in the styles.less file as well, this value will not work, because the variables values of the .../styles/data/.less file are included in the last turn.

Switching to CSS

Assign LESS variables to CSS variables and use them:

:root {
    --cs-menu: @menu;
}

Mixins

Mixins allow to include all the class properties in another class just including the class name as one of the properties value. This is like using variables but in regard to whole classes.

Mixins can behave like functions and take arguments as shown in the following example:

rounded-corners (@radius: 5px) {
border-radius: @radius;
-webkit-border-radius: @radius;
-moz-border-radius: @radius;
}

#header {
.rounded-corners;
}
#footer {
.rounded-corners(10px);
}

The set of mixins from Bootstrap 2.3 is used in CS-Cart. They are stored in the mixins.less file that you can find in the design/themes/responsive/css/tygh directory. In this file there are the utility mixins and component mixins.

  • Utility mixins—simple mixins for specific usage.
  • Component mixins—complex mixins that are used to form the grid.

Mixins allow to write less rules and are used for properties that have prefixs in browsers.

Switching to CSS

  • Before:

    .my-class-rounded() when (@rounded_corners = true) {
        .my-class {
            border-radius: var(--cs-base-border-radius);
        }
    }
    
    .my-class-rounded();
    
  • After:

    // css/tygh/less_functions.less
    .roundedCornersRadiusMixin() when (@rounded_corners = true) {
        --cs-base-rounded-corners-radius: var(--cs-base-border-radius);
    }
    
    .roundedCornersRadiusMixin() when (@rounded_corners = false) {
        --cs-base-rounded-corners-radius: 0;
    }
    
    :root {
        .roundedCornersRadiusMixin();
    }
    
    .my-class {
        border-radius: var(--cs-base-rounded-corners-radius);
    }
    

Operations

This functionality allows using mathematical operations in rules: summation, subtraction, multiplication, and division.

Example:

width: (900 / @columns)px;

Switching to CSS

Take good care when writing math operations in .less files.

Here is a common mistake. If you write:

.my-class {
    width: calc(50% - 10px);
}

then the final CSS will have the following unexpected result:

.my-class {
    width: calc(40%);
}

To avoid this mistake, escape math operations, e.g.:

.my-class {
    width: ~"calc(50% - 10px)";
}

The result is as follows:

.my-class {
    width: calc(50% - 10px);
}

If you want the source LESS code to be CSS-valid, use the following LESS hacks:

  1. Operations, consisting of two elements, one of which is a variable, do not result in an error.

    .my-class {
        width: calc(var(--foo) * 2);
    }
    
  2. Make your expression simple in advance.

    • Before:

      .my-class {
          width: calc(var(--foo) + 10px + 20px);
      }
      
    • After:

      .my-class {
          width: calc(var(--foo) + 30px);
      }
      
  3. Assign a value of a different type to a variable.

    • Before:

      .my-class {
          width: calc(50% + 10px);
      }
      
    • After:

      .my-class {
          --my-class-percent: 50%;
      
          width: calc(var(--my-class-percent) + 10px);
      }
      
  4. Split one expression into several ones.

    • Before:

      .my-class {
          width: calc(var(--foo) + var(--bar) + 10px);
      }
      
    • After:

      .my-class {
          --my-class-part-1: var(--foo) + var(--bar);
          --my-class-part-2: 10px;
      
          width: calc(var(--my-class-part-1) + var(--my-class-part-2));
      }
      

Check your final CSS to ensure its correct behaviour.

Functions

LESS contains a set of functions for working with color, mathematical functions, functions for working with strings.

Operations that are used in CS-Cart:

  • lighten(@color, 10%)—returns the color that is 10% lighter than the current color.
  • darken(@color, 10%)—returns the color that is 10% darker than the current color.

These operations are related to Styles and Theme Editor. With one base color it is possible to change colors of other elements by making base color lighter or darker.

  • percentage(0.5)—converts value to percents. Used while creating grid and columns.

Switching to CSS

  • Before:

    .my-class {
        background: darken(@menu, 5%);
    }
    
  • After:

    // styles/data/Nova_theme.less
    @menu_hover: darken(@menu, 5%);
    
    // css/tygh/less_functions.less
    :root {
        --cs-menu-hover: @menu_hover;
    }
    
    .my-class {
        background: var(--cs-menu-hover);
    }
    

Nested rules

This functionality allows inclosing one rules in another. Nested rules are not often used in CS-Cart, as it complicates the rule working with developer tools in browsers. When looking for nested rules copied from developer tools, it is necessary to take into account a parent rule.

Switching to CSS

Do not use nested rules. Instead of the following:

#header {
    color: black;
    .navigation {
        font-size: 12px;
    }
    .logo {
        width: 300px;
    }
}

write a normal CSS:

#header {
  color: black;
}
#header .navigation {
  font-size: 12px;
}
#header .logo {
  width: 300px;
}

Learn more about other LESS opportunities at the official LESS website.

Please note that not all of them work in CS-Cart.

Directories and Files Structure

The path to a theme css directory is design/themes/THEME_NAME.

  • The css/addons directory—add-on styles.
  • The css/lib directory—side developers’ styles. There are the jquery library styles.
  • The css/tygh directory—supporting styles.
    • css/tygh/reset.less—styles reset. Normalize.css is used.
    • css/tygh/print.less—styles for print.
    • ss/flags.less—styles for showing countries flags.
    • css/design_mode.less—styles that are used in templates and translation mode.
    • css/theme_editor.less—styles that are used in the Theme Editor.
    • css/grid.css—language variables and mixins that are used to form the grid for the fixed layout.
    • css/mixins.less—set of LESS mixins.
  • The css/hooks directory—hooks styles with imports:
    • styles/imports.post.less—after imports.
    • styles/common.post.less—after common styles (tag styles, buttons, helper classes, form, etc).
    • styles/main.post.less—after main styles (main entry point).
    • styles/index.post.less—after last imports (lite checkout, bottom panel, previewer, phone, etc).
    • responsive/index.post.less—after responsive styles.
    • rtl/index.post.less—after RTL styles.

The following is available in Nova Theme only:

  • The css/blocks directory—blocks styles (products, product filters, list templates, wrappers, etc).
  • The css/common directory—common styles (buttons, inputs, tables, pagination, sorting, etc).
  • The css/components directory—components styles (navbar mobile).
  • The css/views directory—views styles (products, categories, checkout, companies, pages, etc).

Styles that are used for the Responsive layout:

  • css/responsive-utilities.less—bootstrap classes that are used to display or hide content for different screen resolutions.
  • css/responsive.less—styles that are used for different screen resolutions.

The main file is styles.less. It contains theme styles. Files that are stored in css/tygh are included in styles.less with the @import operator.

Style Files (.css and .less) Including Order

  • All the .css files are included through hooks: pre (that are added by an add-on).
  • All the .css files are included in the order as they are defined in the file: design/themes/basic/templates/common/styles.tpl
  • All the .css files are included through hooks: post (that are added by an add-on).
  • All the .less files are included through hooks: pre (that are added by an add-on).
  • All the .less files are included in the order as they are defined in the file: design/themes/basic/templates/common/styles.tpl
  • All the .less files are included through hooks: post (that are added by an add-on).
  • All the inline styles that are added to the design/themes/basic/templates/common/styles.tpl template with the <style></style> tag.
  • The preset .less file is included.
  • All the styles added to the Custom CSS field in the Theme Editor.

Hooks including styles are processed in the order that is defined by priority.

All files are gathered in one css. This is done to cut the number of requests.

There is one inconvenience in searching for the style because of gathering all files in one—it is impossible to find the file and the line where a style is situated when using the dev tools.