Home > Web Front-end > CSS Tutorial > Can Less variables like @navBarHeight be thematized?

Can Less variables like @navBarHeight be thematized?

Patricia Arquette
Release: 2024-11-06 07:51:02
Original
535 people have browsed it

Can Less variables like @navBarHeight be thematized?

The Art of Thematization in Less

When developing an app, frequent visual modifications are inevitable as we strive towards customer validation. Preserving certain page aesthetics (themes) for quick customer presentation is desirable.

One approach involves creating appearance classes applied to the body element, allowing for swift page transformations. This begs the question: can Less variables such as @navBarHeight be thematized?

Customizable Theming with Less

The feasibility of this depends on the extent of style and variable variations between themes. A simple starting point:

@themes: (
    blue   rgb( 41, 128, 185),
    marine rgb( 22, 160, 133),
    green  rgb( 39, 174,  96),
    orange rgb(211,  84,   0),
    red    rgb(192,  57,  43),
    purple rgb(142,  68, 173)
);

#navBar {
    .themed(background-color);
}

.themed(@property) {
    .for(@themes); .-each(@theme) {
        @name:  extract(@theme, 1);
        @color: extract(@theme, 2);

        .theme-@{name} & {
            @{property}: @color;
        }
    }
}
Copy after login

Beyond Basics: Enhanced Customization

Employing techniques like Pattern Matching and Ruleset Arguments enables automated generation of complex theme hierarchies. Consider this example:

#navBar {
    .themed({
        color:            @fore-color;
        background-color: @back-color;
    });
}

.theme(@name: green) {
    @fore-color: green;
    @back-color: spin(@fore-color, 180);
    .apply();
}

.theme(@name: blue) {
    @fore-color: blue;
    @back-color: (#fff - @fore-color);
    .apply();
}

.theme(@name: black-and-white) {
    @fore-color: black;
    @back-color: white;
    .apply();
}
Copy after login

This allows for a highly adaptable theming system tailored to specific design requirements. With Less, the possibilities for flexible thematization are endless.

The above is the detailed content of Can Less variables like @navBarHeight be thematized?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template