{"id":11399,"date":"2019-07-18T12:08:31","date_gmt":"2019-07-18T10:08:31","guid":{"rendered":"https:\/\/hesmid.nl\/test\/?p=11399"},"modified":"2019-07-18T12:11:19","modified_gmt":"2019-07-18T10:11:19","slug":"rfs-responsive-font-size","status":"publish","type":"post","link":"https:\/\/hesmid.nl\/test\/rfs-responsive-font-size\/","title":{"rendered":"RFS (Responsive Font Size)"},"content":{"rendered":"\n<p>Just found out about RFS and it sounds really handy. <\/p>\n\n\n\n<p><a href=\"https:\/\/github.com\/twbs\/rfs\">Responsive Font Size<\/a> (RFS) is an engine that <strong>automatically calculates and updates<\/strong> the <code>font-size<\/code> property on elements based on the dimensions of the browser viewport.\n\n<\/p>\n\n\n\n<p>It\u2019s compatible with Sass, Less, Stylus and PostCSS, so it plugs into just about any stack. You can compile Bootstrap 4 with it too simply by changing <code>$enable-responsive-font-sizes<\/code> to <code>true<\/code> (see below). In BS5 this will be enabled by default. See <a href=\"https:\/\/css-tricks.com\/using-a-mixin-to-take-the-math-out-of-responsive-font-sizes\/\">this<\/a> CSS Tricks article. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How does it work?<\/h3>\n\n\n\n<figure class=\"wp-block-image is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/css-tricks.com\/wp-content\/uploads\/2019\/03\/s_982851817502A5ABFAC6BAAFF4F17790218BE0B0FED31AD02B612E9B56244442_1551909001834_rfs-graph2.svg\" alt=\"\" width=\"613\" height=\"351\"\/><\/figure>\n\n\n\n<!--more-->\n\n\n\n<p>Let&#8217;s focus on the black line. As you can see it is the biggest font size of the bunch with a maximum of 60px and a minimum of around 24px. Notice also that it will always be slightly bigger than the other font sizes even on a very small screen.  <\/p>\n\n\n\n<p><strong>Including a font-size is&nbsp;simple:<\/strong><\/p>\n\n\n\n<p><code>.scss<\/code> syntax:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"436\" height=\"328\" src=\"https:\/\/hesmid.nl\/test\/wp-content\/uploads\/2019\/07\/image-14.png\" alt=\"\" class=\"wp-image-11407\" srcset=\"https:\/\/hesmid.nl\/test\/wp-content\/uploads\/2019\/07\/image-14.png 436w, https:\/\/hesmid.nl\/test\/wp-content\/uploads\/2019\/07\/image-14-150x113.png 150w, https:\/\/hesmid.nl\/test\/wp-content\/uploads\/2019\/07\/image-14-300x226.png 300w\" sizes=\"(max-width: 436px) 100vw, 436px\" \/><\/figure>\n\n\n\n<p>The value you pass to the mixin is the <em>maximum<\/em> size of the element which. The maximum size will be applied when the viewport is 1200px is wider.<\/p>\n\n\n\n<p><strong>The Generated CSS:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"497\" height=\"272\" src=\"https:\/\/hesmid.nl\/test\/wp-content\/uploads\/2019\/07\/image-15.png\" alt=\"\" class=\"wp-image-11408\" srcset=\"https:\/\/hesmid.nl\/test\/wp-content\/uploads\/2019\/07\/image-15.png 497w, https:\/\/hesmid.nl\/test\/wp-content\/uploads\/2019\/07\/image-15-150x82.png 150w, https:\/\/hesmid.nl\/test\/wp-content\/uploads\/2019\/07\/image-15-300x164.png 300w\" sizes=\"(max-width: 497px) 100vw, 497px\" \/><\/figure>\n\n\n\n<p>If you are interested in how it works: it&#8217;s just a <a href=\"https:\/\/github.com\/twbs\/rfs\/blob\/master\/scss.scss\">bit of math<\/a> <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Good to know<\/h3>\n\n\n\n<ul><li><a href=\"https:\/\/github.com\/twbs\/rfs\/blob\/master\/scss.scss\"><\/a><strong>RFS only applies <\/strong>to font sizes<strong> above the base font size <\/strong>($rfs-base-font-size in scss\/sass) which is 1.25rem (20px in most browser configurations) out of the box. Everything below that size (e.g. normal body text) will not be managed by RFS. <\/li><li> The <strong>output font size<\/strong> will be rendered in <strong>rem<\/strong>. You can change it to <code>px<\/code> (see <em>configuration<\/em> on Github) but it will disable the ability for users to change the the font size in their browser. <\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Configuration<\/h3>\n\n\n\n<p>RFS works out of the box without any configuration tweaks, but if you  feel the urge to go loco and fine tune the way font sizes are rescaled,  you can.<br><br><strong>The most important settings:<\/strong><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Base font size <sub><sup>(unit in <code>px<\/code> or <code>rem<\/code>)<\/sup><\/sub><\/h4>\n\n\n\n<p>SCSS, Sass &amp; Stylus: <code>$rfs-base-font-size<\/code><\/p>\n\n\n\n<p>The option will prevent the font size from becoming too small on \nsmaller screens. If the font size which is passed to RFS is smaller than\n this base font size, no fluid font rescaling will take place.<\/p>\n\n\n\n<p><em>Default value: <code>1.25rem<\/code><\/em><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Breakpoint <sub><sup>(in <code>px<\/code>, <code>em<\/code> or <code>rem<\/code>)<\/sup><\/sub><\/h4>\n\n\n\n<p>SCSS, Sass &amp; Stylus: <code>$rfs-breakpoint<\/code><\/p>\n\n\n\n<p>Above this breakpoint, the font size will be equal to the font size  you passed to RFS; below the breakpoint, the font size will dynamically  scale.<\/p>\n\n\n\n<p><em>Default value: <code>1200px<\/code><\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Factor <sub><sup>(number)<\/sup><\/sub><\/h3>\n\n\n\n<p>SCSS, Sass &amp; Stylus: <code>$rfs-factor<\/code><\/p>\n\n\n\n<p>This value determines the strength of font size resizing. The higher \nthe factor, the less difference there is between font sizes on small \nscreens. The lower the factor, the less influence RFS has, which results\n in bigger font sizes for small screens. The factor must me greater than\n 1.<\/p>\n\n\n\n<p><em>Default value: <code>10<\/code><\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Class <sub><sup>(boolean)<\/sup><\/sub><\/h3>\n\n\n\n<p>SCSS, Sass &amp; Stylus: <code>$rfs-class<\/code><\/p>\n\n\n\n<p>RFS can be enabled or disabled with a class. There are 3 options:<\/p>\n\n\n\n<ul><li><code>false<\/code>\nNo extra classes are generated.<\/li><li><code>disable<\/code>\nWhen the the disable classes are generated you can add the <code>.disable-responsive-font-size<\/code> class to an element to disable responsive font sizes for the element and its child elements.<\/li><li><code>enable<\/code>\nRFS is disabled by default in this case. The <code>.enable-responsive-font-size<\/code> class can be added to an element to enable responsive font sizes for the element and its child elements.<\/li><\/ul>\n\n\n\n<p><em>Default value: <code>false<\/code><\/em><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Safari iframe resize bug fix <sub><sup>(boolean)<\/sup><\/sub><\/h4>\n\n\n\n<p>SCSS, Sass &amp; Stylus: <code>$rfs-safari-iframe-resize-bug-fix<\/code><\/p>\n\n\n\n<p>Safari doesn&#8217;t resize its font size in an iframe if the iframe is resized. To fix this <code>min-width: 0vw<\/code> can be added and that&#8217;s what happens if this option is enabled. See <a href=\"https:\/\/github.com\/twbs\/rfs\/issues\/14\">#14<\/a>.<\/p>\n\n\n\n<p><em>Default value: <code>false<\/code><\/em><\/p>\n\n\n\n<h4 class=\"wp-block-heading\">!important usage<\/h4>\n\n\n\n<p>By setting a second parameter to true, <code>!important<\/code> is added after the font-size value. (Example is in <code>scss<\/code>)<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.label {\n  @include responsive-font-size(2.5rem, true);\n}<\/pre>\n\n\n\n<p>CSS:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.label {\n  font-size: 2.5rem !important;\n}\n\n@media (max-width: 1200px) {\n  .label {\n    font-size: calc(1.375rem + 1.5vw) !important;\n  }\n}<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Best practices<\/h3>\n\n\n\n<ul><li>Don&#8217;t set RFS on the <code>html<\/code> element, because this influences the value of <code>rem<\/code> and could lead to unexpected results.<\/li><li>Always set your line-heights relative (in <code>em<\/code> or unitless) to prevent interline issues.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Installation<\/h3>\n\n\n\n<p>RFS can be installed using a package manager (recommended):<\/p>\n\n\n\n<ul><li>npm: <code>npm install rfs<\/code><\/li><li>yarn: <code>yarn add rfs<\/code><\/li><li>bower (deprecated): <code>bower install rfs --save<\/code><\/li><\/ul>\n\n\n\n<p>If you&#8217;re using Webpack, you can simplify the <code>@import<\/code> using the <code>~<\/code> prefix:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@import \"~rfs\/scss\";<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Responsive font sizes in Bootstrap 4<\/strong><\/h3>\n\n\n\n<p>Bootstrap v4.3 ships with the option to enable responsive font sizes,\n allowing text to scale more naturally across device and viewport sizes.\n <abbr title=\"Responsive font sizes\">RFS<\/abbr> can be enabled by changing the <code>$enable-responsive-font-sizes<\/code> Sass variable to <code>true<\/code> and recompiling Bootstrap.<\/p>\n\n\n\n<p>To support <abbr title=\"Responsive font sizes\">RFS<\/abbr>, we use a Sass mixin to replace our normal <code>font-size<\/code> properties. Responsive font sizes will be compiled into <code>calc()<\/code> functions with a mix of <code>rem<\/code> and viewport units to enable the responsive scaling behavior. More about <abbr title=\"Responsive font sizes\">RFS<\/abbr> and its configuration can be found on its <a href=\"https:\/\/github.com\/twbs\/rfs\">GitHub repository<\/a>.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just found out about RFS and it sounds really handy. Responsive Font Size (RFS) is an engine that automatically calculates and updates the font-size property on elements based on the dimensions of the browser viewport. It\u2019s compatible with Sass, Less, Stylus and PostCSS, so it plugs into just about any stack. You can compile Bootstrap [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/posts\/11399"}],"collection":[{"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/comments?post=11399"}],"version-history":[{"count":3,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/posts\/11399\/revisions"}],"predecessor-version":[{"id":11411,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/posts\/11399\/revisions\/11411"}],"wp:attachment":[{"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/media?parent=11399"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/categories?post=11399"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/hesmid.nl\/test\/wp-json\/wp\/v2\/tags?post=11399"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}