HiveBrain v1.2.0
Get Started
← Back to all entries
patterncssMinor

Mixin, @extend or (silent) class?

Submitted by: @import:stackexchange-codereview··
0
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 width, font-size etc.

I would like to optimize my code and do one of the following:

  1. Use an extendable silent class



%main-section{
    width: 100%;
    //... more styles
}

.about {
    // this is a main-section
    @extend %main-section;
}


  1. mixin



@mixin main-section($text-color, $bg-color) {

  //some paramaters would provide a flexible module
  width: 100%;
  // etc.
}


  1. 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)

Context

StackExchange Code Review Q#26003, answer score: 2

Revisions (0)

No revisions yet.