Skip to content

Instantly share code, notes, and snippets.

@phloe
Last active May 3, 2016 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phloe/2639919b07868ac6c315 to your computer and use it in GitHub Desktop.
Save phloe/2639919b07868ac6c315 to your computer and use it in GitHub Desktop.

Proper separation of concerns

Let's say you need to add a button to a subscription form.

The naive pee-your-pants way

<button style="background-color: red; width: 200px;">Subscribe</button>

Separation of concerns - part 1

<button class="big-red-button">Subscribe</button>
.big-red-button {
    background-color: red;
    width: 200px;
}

Making stuff generic with utility classes

<button class="button-danger button-large">Subscribe</button>
.button-danger {
    background-color: red;
}

.button-large {
    width: 200px;
}

Final

<button class="subscription-button">Subscribe</button>

Using custom property sets:

:root {
    --button-danger: {
        background-color: red;
    }
    
    --button-large: {
        width: 200px;
    }
}

.subscription-button {
    @apply: --button-danger;
    @apply: --button-large;
}

or using LESS syntax:

.button-danger () {
    background-color: red;
}

.button-large () {
    width: 200px;
}

.subscription-button {
    .button-danger;
    .button-large;
}

or

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment