Sass utilities for the frontend laborer.

  • By David Clark
  • Last update: Dec 15, 2022
  • Comments: 11

Scut

— a collection of Sass utilities to ease and improve our implementations of common style-code patterns.

For a prolonged introduction to Scut, read "Introducing Scut" on CSS-Tricks.

If you have any questions about Sass, they are answered in Sass's fine documentation.

Installing and Using

Please visit the complete documentation here:
http://davidtheclark.github.io/scut/

Usage should be explained there, as is installation. But I'll explain installation here, too, for your convenience. You can install Scut by:

  • Using Bower: bower install scut --save-dev.
  • Downloading the file from the latest release.
  • Using Scut as a Compass extension by installing the RubyGem (gem install scut) and then performing the usual Compass require and @import business.
  • Using node-sass and eyeglass:
    • npm install --save-dev scut
    • setup render per eyeglass instructions
    • in sass files: @import 'scut'

Contributing

Please do! Scut is simple; contributing should be easy. So give it a go.

If you have any questions, if anything about this document is unclear or inaccurate, if you can't figure out what to do, please file an issue or contact me.

Approach

Scut utilities should help users avoid repetition, organize code, and re-use code.

Scut utilities should tackle patterns that suffer from one or more of the following problems:

  1. The pattern is non-intuitive.
  2. The pattern deserves a shorthand.
  3. The pattern involves some important best practices.
  4. The pattern is extremely common and (at least) a little annoying.

The utility's goal is to fix those problems in a way that maximizies reusability. Here are some principles to keep in mind to maximize that reusability:

  • Include sufficient detail to implement the pattern, but no more.
  • Use arguments to allow for typical variations on the theme.
  • Arrange those arguments according to the likelihood that users will want to change them.
  • Namespace (notice the scut- prefix everwhere).
  • Document thoroughly.

I go into detail about all these ideas in that CSS-Tricks article.

Development Requirements

Writing Scut Utilities

The utilities are in src/, organized by category. The SCSS stylesheets in src/ ultimately concatenate into dist/_scut.scss, which is what users @import into their own Sass.

Scut's SCSS Styleguide

Please have a look at existing SCSS files within src/ and try to match their style.

(Or, if you think there's a better way to do things, please file an issue.)

Here are some guidelines to explain how I've been writing:

  • Head the file with a multi-line comment (each line an inline // comment, not a block comment) naming the utility and listing any dependencies. Limit dependencies please. In the end, that top comment should also contain the URL of the utility's documentation. For example:
// SCUT PIXELS TO EMS
// http://davidtheclark.github.io/scut/#pixels-to-ems

// Depends on `scut-strip-unit`.
  • Indent with two spaces.
  • List arguments on separate lines, so they are easy to scan. For example:
@mixin scut-color-swap (
  $inactive,
  $active,
  $duration: 0,
  $bg: false
) {
  // mixin content
}
  • Space liberally. A space at the beginning and end of mixins and functions helps distinguish the arguments from the inner workings. Spacing can also help delineate different "sections" of the code by grouping rules that work together and separating those with different roles.

Experimenting and Testing

The method I recommend for experimentation and testing is to use Codepen, either starting your own pen from scratch or forking the Scut Playground (which imports the latest version of Scut).

(I have deleted the "tests" directory and tasks from the repository in favor of relying on Codepen.)

Documenting

Documentation is compiled using Assemble. The source files are located in docs/content and docs/dev. You'll need to bower install to get Normalize.

Github

https://github.com/davidtheclark/scut

Comments(11)

  • 1

    Anybody want to be a project maintainer?

    I haven't been using Sass for a little while so my attention to this library has diminished. I am looking for at least one other person to help maintain it -- preferably an active user of it.

    Does anybody want to join in?

  • 2

    Release Scut as a Compass extension

    There are thousands and thousands of web developers who leverage the Compass ecosystem of Sass extensions. I believe there are way more people who use Sass with Compass than Sass with Bower:

    http://www.google.com/trends/explore?q=sass+compass%2C+sass+bower

    So please release Scut as a Compass extension. This requires like 20 minutes of your time, but you'll have to keep it up to date.

    Also, you should tag commits that get released with corresponding version numbers. See http://semver.org/ .

  • 3

    Docs crash iOS browsers ... sometimes?

    I've received a couple of complaints that the docs are crashing people's iOS browsers (both Safari and Chrome, both iPhone and iPad).

    This is strange, considering how simple the site is.

    It was happening earlier in development and I tried a few things (making sure HTML validated and removing unnecessary resources):

    • https://github.com/davidtheclark/scut/commit/cdbaa9f81f85f6637f452c3f1346f35531e413e4
    • https://github.com/davidtheclark/scut/commit/0bc2f1ef72027d214c9a840b1478b3dd81cc2381
    • https://github.com/davidtheclark/scut/commit/69c9e86bbee148153c0052b55832dc1e098885bf

    I thought it was fixed because I was no longer able to reproduce the crash. But others seem to be able to.

    So if you are having this problem and are able to troubleshoot in any way, please help out!

  • 4

    Alternative Sticky Footer

    Hi, I've been researching sticky footers lately and I wondered what you thought of this approach:

    http://www.joshrcook.com/a-responsive-sticky-footer/

    It's the best solution I've found to date - you don't need to know the height of the footer and it works in IE8+ and in everything else I've tried. I haven't found any issues with it yet, and wondered if it could be included in Scut as an alternative approach?

    Happy to discuss / research more etc. and provide a PR if you think this is worth it.

    Cheers

  • 5

    Allow multiple "inner" values for semantic markup on scut-vcenter-td mixin

    I'm finding that the "cells" of my table-based vertical centering solution don't have a common selector and I'd rather not have to put a "scut-inner" or similar class on them. By updating the scut-vcenter-td @mixin to take a variable number of selectors, we can support different selectors for the inner and use the tag/class that is already in the markup without needing to introduce a non-semantic class.

    If no list is provided, it still falls back to the .scut-inner selector.

  • 6

    Make compatible with sass eyeglass

    It would be nice to make this also compatible with the new upcoming sass eyeglass. https://github.com/sass-eyeglass/eyeglass#writing-an-eyeglass-module-with-sass-files

  • 7

    a : unstyled (or link : unstyled)

    Throwing out a tiny mixin to possibly include, for resetting the styling of anchor tags.

    I regularly need to reset styling for <a> tags at the class-level, like so:

    .my-link-class {
        text-decoration: none;
        color: inherit;
    }
    

    I've made a tiny mix-in for it, inspired by scut-list-unstyled. I reach for both of these regularly.

    Any interest? Would be quick for me to whip up.

  • 8

    fill alternative like background-size cover

    What about this for your great collection:

    /* merge with above css */
    .parent-element-to-video {
        position: relative; /* or absolute or fixed */
    }
    video {
        position: absolute;
        left: 50%; /* % of surrounding element */
        top: 50%;
        transform: translate(-50%, -50%); /* % of current element */
    }
    

    source excample: http://stackoverflow.com/questions/10797632/simulate-background-sizecover-on-video-or-img

    this is a great alternative for backgrond-size: cover; for any html elements like img, video, or just a div. works great cross all browsers since ie9+

  • 9

    conflict scut-list-custom -> scut-list-divided

    if I use :

    ul {
            @include scut-list-custom("\00bb", 1.3em, .5em);
    }
    

    and later on:

    .pagination ul {
            @include scut-list-divided("\00B7", 0.2em);
    }
    

    it will not work, as ul has styles set, which should be reset by scut-list-divided to work / overwrite.

    it is:

    /* reset list styling set by @include scut-list-custom */
    ul > li:before {
                position: static;
                width: auto;
                content: '';
    }
    
  • 10

    Performance enhancements to prevent crashes

    So it turns out it mightn't have been overthrow.js at all.

    I digged a little further into the crashing issue and I found that on desktop, when scrolling, the FPS were continuously maxing out at and above 60FPS (this would be 2x3 times on mobile). On resource-lacking devices this could potentially cause the browser to crash.

    The primary cause was that both the .list and .main divs were both set to position: absolute which meant that the whole page was being repainted on scroll. I've reduced this a bit by doing the following:

    • .list no longer uses position: absolute, now uses position: fixed.
    • .list uses the translateZ hack to hoist it to the GPU for better FPS when scrolling
    • .main no longer uses position: absolute, instead it is default position with padding-left: 16em.

    If you do a before and after, measuring the frame rate on scroll you'll see it's a lot more respectable. You can read more about the background on this here

    A few things to note.

    • I haven't actually been able to test this on my mobile device as I'm having issues getting it to see my local environment. I've only tested it in the browser
    • I wasn't sure what you're preferred way of doing auto-prefixing CSS was, so I just input all the possible css values.
  • 11

    Vertical centering with transform translate

    Added another vertical-center mixin that archieves it with transform: translate.

    It does not require any width or height which makes it ideal in some environments-

    downside: It does not work in IE8 and below