Skip to content

Instantly share code, notes, and snippets.

View narekmal's full-sized avatar

Narek Malkhasyan narekmal

View GitHub Profile
@narekmal
narekmal / Description.md
Last active July 25, 2022 06:19
SCSS utilities for using vw units

The Function

Suppose we want a div to have 50px width when the screen width is 500px and a proportionate width when the screen width changes. We do math: (50/500)*100 = 10 and set width: 10vw. The following simple function helps make our intention more clear:

@function get-vw($valueAtWidth, $width) {
    @return $valueAtWidth*100vw/$width;
}

Usage: width: get-vw(50px, 500px);