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; } } }
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(); }
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!