Skip to content

Instantly share code, notes, and snippets.

@Tenderfeel
Created September 12, 2018 20:31
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 Tenderfeel/b17963f6491962d91e5c7e8c6f71ab55 to your computer and use it in GitHub Desktop.
Save Tenderfeel/b17963f6491962d91e5c7e8c6f71ab55 to your computer and use it in GitHub Desktop.
Sass Responsive Mixins
@function percentage-vw($num) {
$per: ($num * 100);
@return #{$per}vw;
}
@mixin responsive-width($width, $base: 750px) {
width: percentage($width / $base);
max-width: $width;
}
@mixin responsive-height($width, $height) {
height: percentage($height / $width);
max-height: $height;
}
@mixin responsive-spacer($width, $height) {
&::before {
content: '';
display: block;
padding-top: percentage($height / $width);
float: left;
}
}
//@include responsive(image-width($img), image-height($img));
@mixin responsive($width, $height, $base: 750px, $size: true, $spacer: true) {
@if ($size == true) {
background-size: contain;
}
width: percentage($width / $base);
max-width: $width;
max-height: $height;
overflow: hidden;
@if($spacer == true) {
@include responsive-spacer($width, $height);
}
}
@mixin clear-responsive() {
max-width: 100%;
max-height: 100%;
&::before {
display: none;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment