Skip to content

Instantly share code, notes, and snippets.

@peduarte
Last active August 31, 2018 03:20
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peduarte/68153970739a753a5dbc to your computer and use it in GitHub Desktop.
Save peduarte/68153970739a753a5dbc to your computer and use it in GitHub Desktop.
Modernizr CSS3 Sizing Values check (min-content, max-content, fill-content, fill-available)
(function(Modernizr) {
'use strict';
/**
* Modernizr test to check if CSS3 Sizing values are supported
* W3: http://www.w3.org/TR/css3-sizing/
* CanIUse: http://caniuse.com/#feat=intrinsic-width
*
* Values to check:
* min-content
* max-content
* fill-content
* fill-available
*
* Extra check if all of the above are supported:
* sizingvalues
*
*/
var test = function (prop, val) {
var element, property, value;
property = prop + ':';
value = val + ';';
element = document.createElement('div');
element.style.cssText = property + Modernizr._prefixes.join(value + property);
testCount++;
return !!element.style.length;
};
var supportsAll = function (array) {
for (var i = 1; i < array.length; i++) {
if (array[i] !== array[0] || array[i] === false) {
return false;
}
}
return true;
};
var results = [];
var testCount = -1;
Modernizr.addTest('mincontent', function() {
results.push(test('width', 'min-content'));
return results[testCount];
});
Modernizr.addTest('maxcontent', function() {
results.push(test('width', 'max-content'));
return results[testCount];
});
Modernizr.addTest('fillcontent', function() {
results.push(test('width', 'fill-content'));
return results[testCount];
});
Modernizr.addTest('fillavailable', function() {
results.push(test('width', 'fill-available'));
return results[testCount];
});
Modernizr.addTest('sizingvalues', function() {
return supportsAll(results);
});
})(Modernizr);
@brookjordan
Copy link

brookjordan commented Aug 31, 2018

Thanks!

Might be worth adding this to the comment:

/**
 * Requires a Modernizr build with at least:
 *  - addtest
 *  - prefixes

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