Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rfs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartijn Cuppens <martijn.cuppens@intracto.com>2018-01-06 20:49:03 +0300
committerMartijn Cuppens <martijn.cuppens@intracto.com>2018-01-06 20:57:32 +0300
commit84d5b841c52d8d767693413eda6eaaed43f93050 (patch)
treec6cd0c8e41616a402691a42e6872eff027ab1c8f
parent12b2d5f6fe8452a0e7ccf3bbca6729ff6bda6809 (diff)
- switched to rem as default rendering - increased minimum font-size to 1rem - disable-responsive-font-size class
-rw-r--r--README.md69
-rw-r--r--bower.json2
-rw-r--r--package.json2
-rw-r--r--scss/_rfs.scss19
4 files changed, 66 insertions, 26 deletions
diff --git a/README.md b/README.md
index 28f225c..5dfa7c1 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# RFS mixin[![npm][npm-image]][npm-url]
+# Responsive font size mixin [![npm][npm-image]][npm-url]
[npm-image]: https://img.shields.io/npm/v/rfs.svg
[npm-url]: https://npmjs.org/package/rfs
> This package lets you use the `responsive-font-size` mixin which **automatically calculates the appropriate font
@@ -50,47 +50,46 @@ lose the ability to easily and quickly manage and update RFS as a dependency.
This input (SCSS):
```scss
.title {
- @include responsive-font-size(62);
+ @include responsive-font-size(4rem);
+ // OR:
+ // @include responsive-font-size(64px);
+ // OR:
+ // @include responsive-font-size(64);
}
```
Will generate this (CSS):
```css
.title {
- font-size: 62px;
+ font-size: 4rem;
}
@media (max-width: 1200px) {
.title {
- font-size: calc(23.6px + 3.2vw);
+ font-size: calc(1.6rem + 3.2vw);
}
}
```
-In this case a value without unit was passed to the mixin (`62`), which is interpreted as `62px`. It's also possible to
-pass font sizes in rem-units. You can also use `rfs()` instead of `responsive-font-size()` which is a bit
-shorter to type.
+You can also use the `rfs()` alias instead of `responsive-font-size()`.
## Configuration
-![RFS visualisation](https://i.imgur.com/ImJ17Im.png)
-
-There are configuration variables which influence the calculation of the font size. In the graph above the default
-configuration is used.
+![RFS visualisation](https://i.imgur.com/9YciUbb.png)
**$rfs-minimum-font-size:** (in `px` or `rem`)
Font sizes which are calculated by RFS will never be lower than this size. However, you can still pass a smaller font
-size to RFS, but then RFS won't dynamically scale this font size. For example (see graph above): `responsive-font-size(19)` will
-trigger dynamic rescaling, with `responsive-font-size(10)` it will just stay `10px` all the time.
-*Default value: `14px`*
+size to RFS, but then RFS won't dynamically scale this font size. For example: `responsive-font-size(19)` will trigger
+dynamic rescaling, with `responsive-font-size(10)` it will just stay `10px` all the time.
+*Default value: `1rem`*
**$rfs-font-size-unit:** (string)
-The font size will be rendered in this unit. Possible units are `px` and `rem`.
-*Default value: `px`*
+The font size will be rendered in this unit. Possible units are `px` and `rem`.
+*Default value: `rem`*
**$rfs-breakpoint:** (in `px`, `em` or `rem`)
Above this breakpoint, the font size will be equal to the font size you passed to the mixin; below the breakpoint, the
-font size will dynamically scale.
+font size will dynamically scale.
*Default value: `1200px`*
**$rfs-breakpoint-unit:** (string)
@@ -100,7 +99,7 @@ The width of `$rfs-breakpoint` will be rendered in this unit. Possible units are
**$rfs-factor:** (number)
This value determines the strength of font size resizing. The higher `$rfs-factor`, the less difference there is between
font sizes on small screens. The lower `$rfs-factor`, the less influence RFS has, which results in bigger font sizes for
-small screens. `$rfs-factor` must me greater than 1, setting it to 1 will disable dynamic rescaling.
+small screens. `$rfs-factor` must me greater than 1, setting it to 1 will disable dynamic rescaling.
*Default value: `5`*
**$rfs-two-dimensional** (Boolean)
@@ -108,15 +107,43 @@ Enabling the two dimensional media queries will determine the font size based on
`vmin`. This prevents the font size from changing if the device toggles between portrait and landscape mode.
*Default value: `false`*
+**$rfs-generate-disable-classes** (Boolean)
+When the the disable classes are generated you can add the `.disable-responsive-font-size` class to an element to
+disable responsive font sizes for the element and its child elements. If you don't use this, it's better to set this to
+`false` to prevent the generation of unused css. This doesn't apply on font-sizes which are inherited from parents.
+*Default value: `true`*
+
+## !important
+By setting a second parameter to true, `!important` is added after the font-size value.
+
+```scss
+.label {
+ @include responsive-font-size(2.5rem, true);
+}
+```
+
+CSS:
+```css
+.label {
+ font-size: 2.5rem !important;
+}
+
+@media (max-width: 1200px) {
+ .label {
+ font-size: calc(1.3rem + 1.6vw) !important;
+ }
+}
+```
+
## Known issues
-Safari doesn't recalculate the value of vw in a calc()-function for font-sizes in iframes if the min-width, max-width or width is not set in vw after the iframe is resized (edge case, but this is the case for Codepen demo's). Adding this line will solve this:
+Safari doesn't recalculate the value of vw in a calc()-function for font-sizes in iframes if the min-width, max-width or width is not set in vw after the iframe is resized (edge case, but this is the case for Codepen demo's). Adding this line will solve this (dirty fix):
```css
_::-webkit-full-page-media, _:future, :root * {min-width: 0vw;}
```
## Best practices
-- Remember to set RFS on your font size of your `html` or `body`, otherwise some text may not dynamically rescale. Note
-that setting RFS on `html` will influence the value of `rem`.
+- Remember to set RFS on your font size of your `html` or `body`, otherwise some text may not dynamically rescale (if
+`$rfs-minimum-font-size` is decreased). Note that setting RFS on `html` can influence the value of `rem`.
- Always set your line-heights relative (in `em` or unitless).
- More tips and tricks with examples can be found
[on this article](https://medium.com/@martijn.cuppens/magic-font-resizing-with-rfs-b5d781296dd6).
diff --git a/bower.json b/bower.json
index d88d2a1..9a28c64 100644
--- a/bower.json
+++ b/bower.json
@@ -7,8 +7,10 @@
],
"license": "MIT",
"keywords": [
+ "rfs",
"scss",
"responsive",
+ "responsive-font-size",
"font-size",
"typography"
],
diff --git a/package.json b/package.json
index da6ba95..6cdd4c2 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "rfs",
- "version": "6.0.0",
+ "version": "7.0.0",
"description": "A scss-mixin for responsive font-sizes.",
"main": "scss/_rfs.scss",
"scripts": {
diff --git a/scss/_rfs.scss b/scss/_rfs.scss
index 789d23d..6c068cd 100644
--- a/scss/_rfs.scss
+++ b/scss/_rfs.scss
@@ -9,8 +9,8 @@
// Configuration.
// Minimum fontsize.
-$rfs-minimum-font-size: 14px !default;
-$rfs-font-size-unit: px !default;
+$rfs-minimum-font-size: 1rem !default;
+$rfs-font-size-unit: rem !default;
// Breakpoint at where font-size starts decreasing if screen width is smaller.
$rfs-breakpoint: 1200px !default;
@@ -20,7 +20,10 @@ $rfs-breakpoint-unit: px !default;
$rfs-two-dimensional: false !default;
// Factor of decrease.
-$rfs-factor: 5 !default;
+$rfs-factor: 10 !default;
+
+// Generate disable classes
+$rfs-generate-disable-classes: true !default;
// 1 rem = $rfs-rem-value px.
$rfs-rem-value: 16 !default;
@@ -135,6 +138,15 @@ $enable-responsive-font-sizes: true !default;
font-size: $rfs-static;
+ @if $rfs-generate-disable-classes {
+ // Adding an extra class increases specificity,
+ // which prevents the media query to override the font size
+ .disable-responsive-font-size &,
+ &.disable-responsive-font-size {
+ font-size: $rfs-static;
+ }
+ }
+
@if $rfs-two-dimensional {
@media (max-width: #{$mq-value}), (max-height: #{$mq-value}) {
font-size: $rfs-fluid;
@@ -152,4 +164,3 @@ $enable-responsive-font-sizes: true !default;
@mixin responsive-font-size($fs, $important: false) {
@include rfs($fs, $important);
}
-