/less-flexbox

less-flexbox is a collection of Less mixins for CSS3 Flexbox.

Primary LanguageCSSMIT LicenseMIT

less-flexbox

This is a collection of Less mixins for CSS3 Flexbox.

Browser support

Flexbox is supported, in one way or another, by all major browsers. Due to the changes in the spec over time, I've decided to only include support for the "New" Flexbox spec and not for the older "Legacy" spec.

Although Internet Explorer 10 uses different property names (for example, flex-pack instead of justify-content), its flexbox behavior is mostly the same as in other browsers. Also, IE10's alternate grammar doesn't include separate properties for flex-grow, flex-shrink, and flex-basis, so these mixins are not included in this collection.

Usage

You can use less-flexbox by importing it into your Less project. All standard mixins are enclosed in the #flexbox namespace, and all mixin helpers are in the ._flex namespace.

Directly call the mixins you need

The benefit to using this method is that all properties are explicitly output, which may make in-browser debugging easier.

	@import (reference) "flexbox";

	.box {
		// You can explicitly reference the namespace on each mixin call
		#flexbox .display(flex);
		#flexbox .align-items(center);
	}

	.flexy-box {
		// Or you can call the namespace once and save some extra lines
		#flexbox;
			.display(inline-flex);
			.direction(column);
	}

See Namespaces & Ancestors for more information on namespacing in Less.

Extend mixin helpers

The ._flex namespace includes many of the commonly-used property-value pairs available with flexbox. If you use a DRY approach, this method should be familiar.

	@import (reference) "flexbox";

	.box {
		&:extend(
			._flex .display--flex,
			._flex .align-items--center
		);
	}

This method works well when using Less in conjunction with Modernizr.

	.box {
		display: block;

		.flexbox & { // .flexbox .box
			&:extend(._flex .display--flex);
			#flexbox .flex(1, 0, 50%);
		}
	}