Skip to content

Make use of the css min() function #110

@MartijnCuppens

Description

@MartijnCuppens

Hopefully one day the min() function will be implemented by all major browsers and that could simplify RFS a lot. Instead of the mixin, we can make use of a function to generate the value.

For example:

.title {
  padding: rfs(2rem);
  font-size: rfs(4rem);
}

would generate:

.title {
  padding: min(2rem, calc(1.325rem + 0.9vw));
  font-size: min(4rem, calc(1.525rem + 3.3vw));
}

Other positive side effects are:

  • We can use the same syntax in every language (sass, scss, less, stylus & PostCSS)
  • It's a bit more predictable than the mixin because you know it's going to a value and not "some lines of code"
  • Mixins don't work with plugins like stylelint-order, the function would fix this.
  • Custom properties (css variables) can be set to a value which can be reused in css.

Only downside is that the disabled/enabled classes won't work anymore, but I have no clue if this feature is even used.

Currently Safari kind of supports min(), but it's still not perfect when resizing without the safari iframe hack (#14): https://codepen.io/MartijnCuppens/pen/ywaJpW

Browser support

Browser support is still an issue. Browser support so far:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions