How is 'clearfix' implemented within twitter-bootstrap??
Often this is needed to clear image floats and such... What is the proper way to use it within a twitter-bootstrap-constructed website??
Bootstrap's implementation of clearfix is based on the one also used on HTML 5 Boilerplate.
Internally, it's on line 12 of mixins.less:
.clearfix() {
*zoom: 1;
&:before,
&:after {
display: table;
content: "";
}
&:after {
clear: both;
}
}
You use it like you would any other clearfix, right on the parent element that's holding the floats.
From what I understand of your explanation.
html: `
less: .parent { .clearfix(); }
as .clearfix is not to be seen anywhere in the compiled css
That would be correct. You must use clearfix through LESS, as far as I remember, it's only implemented as a mixin (it uses parentheses at the end). LESS does not carry along mixins to compiled CSS, so there is no .clearfix class. You must use the mixin in other rules, and LESS will inject the clearfix mixin straight into that rule.
Just to make that clear, here's an example. First, without using mixins:
.injected { color: red; }
.foo { .injected; }
That would compile to this CSS:
.injected { color: red; }
.foo { color: red; }
Notice that it preserves the .injected class. As for a mixin in LESS:
.injected() { color: red; }
.foo{ .injected(); }
Would compile to:
.foo{ color: red; }
The .injected mixin does not carry over. Same goes for the .cleafix() mixin.
Pushed a fix to 2.0.1-wip for this to enable .clearfix to be used as a class. I highly encourage folks to not use this though in all their markup—use it via LESS whenever possible.