patterncssMinor
Mixin, @extend or (silent) class?
Viewed 0 times
mixinextendclasssilent
Problem
I am struggling with the basic concepts of SASS.
I have a page that has multiple section, all of them are sharing properties like
I would like to optimize my code and do one of the following:
I don't know which one i should choose. Maybe there's even a better solution i didn't mention. What is your opinion?
I have a page that has multiple section, all of them are sharing properties like
width, font-size etc.I would like to optimize my code and do one of the following:
- Use an extendable silent class
%main-section{
width: 100%;
//... more styles
}
.about {
// this is a main-section
@extend %main-section;
}- mixin
@mixin main-section($text-color, $bg-color) {
//some paramaters would provide a flexible module
width: 100%;
// etc.
}- just a simple class to apply in my HTML
.main-section{
width: 100%;
//... more styles
}I don't know which one i should choose. Maybe there's even a better solution i didn't mention. What is your opinion?
Solution
Best solution: Create a single section class and add it to all sections.
Second best solution: Write a specific section class and @extend on other sections (in case you do not have control of HTML)
Worst solution: Writing a mixin (duplicates styles)
Second best solution: Write a specific section class and @extend on other sections (in case you do not have control of HTML)
Worst solution: Writing a mixin (duplicates styles)
Context
StackExchange Code Review Q#26003, answer score: 2
Revisions (0)
No revisions yet.