Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

swapping .clearfix and .clearfix() for css reduction #13538

Closed
Harris-Miller opened this issue May 8, 2014 · 3 comments
Closed

swapping .clearfix and .clearfix() for css reduction #13538

Harris-Miller opened this issue May 8, 2014 · 3 comments
Labels

Comments

@Harris-Miller
Copy link

your current set up is so:

.clearfix() {
  &:before,
  &:after {
    content: " "; // 1
    display: table; // 2
  }
  &:after {
    clear: both;
  }
}

.clearfix {
  .clearfix();
}

consider switching to this:

.clearfix {
  &:before,
  &:after {
    content: " "; // 1
    display: table; // 2
  }
  &:after {
    clear: both;
  }
}

.clearfix() {
  &:extend(.clearfix all);
}

it will reduce the amount of resulting css when devs use your mixin in their own less files. There will still be some duplicate with .clearfix() calling both mixin .clearfix() and selector .clearfix (known issue with less.js, and I do wish you would change .clearfix() to .makeclearfix() or .addclearfix() or whatever to alleviate this problem, but I know you won't).

When the good fellas over at LESS do fix that problem, this code (combined with my suggested change)

.my-class {
  .clearfix();
}

will result in:

.clearfix:before,
.clearfix:after,
.my-class:before,
.my-class:after {
  content: " ";
  display: table;
}
.clearfix:after,
.my-class:after {
  clear: both;
}
.my-class {
  color: blue;
}

and of course if a dev uses .clearfix(); throught their own less files, the resultant compiled css will see a pretty significant reduction in size

@cvrebert
Copy link
Collaborator

cvrebert commented May 8, 2014

Or you could just use

.my-class {
  &:extend(.clearfix all);
}

in your own Less file.

@cvrebert cvrebert changed the title flipping .clearfix and .clearfix() for css reduction swapping .clearfix and .clearfix() for css reduction May 8, 2014
@cvrebert cvrebert added the css label May 8, 2014
@Harris-Miller
Copy link
Author

true. having the mixin still do that would be nice though

@cvrebert cvrebert added this to the v3.2.1 milestone Jun 9, 2014
@mdo mdo removed this from the v3.2.1 milestone Jun 11, 2014
@mdo
Copy link
Member

mdo commented Jun 11, 2014

Yeah, we'll punt this to a v4 thing since our intention is that all mixins should never generate compiled styles on their own. In agreement with you on this though.

@mdo mdo closed this as completed Jun 11, 2014
@mdo mdo mentioned this issue Aug 19, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants