cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

Quick-add: + add another resource

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="o-container">
	<section>
		<h1 class="c-title  u-a-c">
			<span class="c-dis-b u-scalable-1">
				Scalable Text in CSS
			</span>
			<span class="c-dis-b u-scalable-2">
				with Maximum Sizes
			</span>
			<span class="c-dis-b u-scalable-3">
				and Minimum Sizes
			</span>
		</h1>
		<p class="u-scalable-4  u-a-c">
			Scale <code>font-size</code> property based on viewport width using only CSS. The following CSS units will work: <code>em</code>, <code>rem</code>, <code>px</code>, <code>ch</code>, <code>cm</code>, <code>mm</code>, <code>in</code>, <code>pt</code>, <code>pc</code>.
		</p>
	</section>
	
	<hr />
	
	<section>
		<h2 class="u-scalable-3">
			MIXINS
		</h2>
		<p class="u-scalable-4">
			Mixins have up to four values that need to be passed:
		</p>
		<ul class="u-scalable-4">
			<li>
				<b class="c-code">context-width</b>: The identified width that is used as the scaling point.
			</li>
			<li>
				<b class="c-code">base-font-size</b>: The base <code>font-size</code>. When the viewport is equal to <span class="c-code">context-width</span>'s width, the calculated font-size will be equal to <span class="c-code">base-font-size</span>. <span class="c-code">base-font-size</span> has to be a smaller value than <span class="c-code">limit-font-size-max</span> and has to be a larger value than <span class="c-code">limit-font-size-min</span>.
			</li>
			<li>
				<b class="c-code">limit-font-size-min</b>: The minimal size that is intended for <code>font-size</code>. The scaling effect will not allow the font to be smaller than the <span class="c-code">limit-font-size-min</span>. <span class="c-code">limit-font-size-min</span> has to be a smaller value than <span class="c-code">base-font-size</span>.
			</li>
			<li>
				<b class="c-code">limit-font-size-max</b>: The maximum size that is intended for <code>font-size</code>. The scaling effect will not allow the font to be larger than the <span class="c-code">limit-font-size-max</span>.  <span class="c-code">limit-font-size-max</span> has to be a larger value than <span class="c-code">base-font-size</span>.
			</li>
		</ul>
		<p>
			<b>Note</b>: All values need to be the same unit type.
		</p>
		<article>
			<h3 class="u-scalable-3">
				<span class="c-code">scaleFont()</span>
			</h3>
			<p class="u-scalable-4">
				Scales font &quot;up&quot; as browser gets wider with a maximum set <code>font-size</code> and scales font &quot;down&quot; as browser gets thinner with a minimum set <code>font-size</code>.
			</p>
			<p class="u-scalable-4">
				<code>
					@include scaleFont(context-width, base-font-size, limit-font-size-min, limit-font-size-max);
				</code>
			</p>
<pre class="u-scalable-4">
.selector-name { // apply to any selector

	@include scaleFont(62.5rem, 4rem, 1.875rem, 6.25rem);
	// 4 required arguments*:
	// 62.5rem: context-width
	// 4rem: base-font-size
	// 1.875rem: limit-font-size-min
	// 6.25rem: limit-font-size-max
	// *All values need to be the same unit type
}</pre>
		</article>
		<article>
			<h3 class="u-scalable-3">
				<span class="c-code">scaleFontUp()</span>
			</h3>
			<p class="u-scalable-4">
				Scales font &quot;up&quot; as browser gets wider with a maximum set <code>font-size</code>.
			</p>
			<p class="u-scalable-4">
				<code>
					@include scaleFontUp(context-width, base-font-size, limit-font-size-max);
				</code>
			</p>
<pre class="u-scalable-4">
.selector-name { // apply to any selector

	@include scaleFontUp(62.5rem, 4rem, 6.25rem);
	// 3 required arguments*:
	// 62.5rem: context-width
	// 4rem: base-font-size
	// 6.25rem: limit-font-size-max
	// *All values need to be the same unit type
}</pre>
		</article>
		<article>
			<h3 class="u-scalable-3">
				<span class="c-code">scaleFontDown()</span>
			</h3>
			<p class="u-scalable-4">
				Scales font &quot;down&quot; as browser gets thinner with a minimum set <code>font-size</code>.
			</p>
			<p class="u-scalable-4">
				<code>
					@include scaleFontDown(context-width, base-font-size, limit-font-size-min);
				</code>
			</p>
<pre class="u-scalable-4">
.selector-name { // apply to any selector

	@include scaleFontDown(62.5rem, 4rem,  1.875rem);
	// 3 required arguments*:
	// 62.5rem: context-width
	// 4rem: base-font-size
	// 1.875rem: limit-font-size-min
	// *All values need to be the same unit type
}</pre>
		</article>
	</section>
</div>
            
          
!
            
              /*! * [Scalable Text in CSS with Maximum and Minimum Sizes](https://github.com/kevinmack18/SCALABLE-TEXT-IN-CSS) */
 // * Github: https://github.com/kevinmack18/SCALABLE-TEXT-IN-CSS
 // * Released under the MIT license
 // * https://github.com/kevinmack18/SCALABLE-TEXT-IN-CSS/blob/master/LICENSE
 // * Version: v1.0.1
 // * Date: 2016-01-11

@mixin calcScalableFont($context-width, $base-font-size, $limit-font-size, $scale) {
	$scaleFactor: if(($scale == down), true, false); // determine direction of scale
	$scaleBoth: if(($scaleFactor == false and $scale != up), true, false); // scales "up and down"
	$limit-font-size-min: if($scaleBoth, $scale, false); // only if using "up and down" scale
	$max-width: ($limit-font-size / ($base-font-size / $context-width)); // width to calculate scaling
	$min-width: if(($limit-font-size-min), ($limit-font-size-min / ($base-font-size / $context-width)), $max-width);
	
	@media screen and (if($scaleFactor, min-width, max-width): $context-width) {
		@if ($scaleBoth) {	
			@media screen and (max-width: $min-width)  {
				font-size: $limit-font-size-min;
			}		
		} @else {
			font-size: $base-font-size;
		}
	}
	
	@if ($scaleBoth) {
		@media screen and (if($scaleFactor, max-width, min-width): $context-width) and (min-width: $min-width), screen and (if($scaleFactor, min-width, max-width): $context-width) and (min-width: $min-width) { 
			font-size: (($base-font-size / $context-width) * 100)#{vw};
		}
	}

	@media screen and (if($scaleFactor, max-width, min-width): $context-width) {
		@if ($scaleBoth == false) {
			@media screen and (if($scaleFactor, min-width, max-width): $max-width)  { 
				font-size: (($base-font-size / $context-width) * 100)#{vw};
			}
		}
		@media screen and (if($scaleFactor, max-width, min-width): $max-width) {
			font-size: $limit-font-size; // don't go below 16px!
		}
	}
}

@mixin scaleFont($context-width, $base-font-size, $limit-font-size-min, $limit-font-size-max) {
	@include calcScalableFont($context-width, $base-font-size, $limit-font-size-max, $limit-font-size-min);
}

@mixin scaleFontUp($context-width, $base-font-size, $limit-font-size) {
	@include calcScalableFont($context-width, $base-font-size, $limit-font-size, up);
}

@mixin scaleFontDown($context-width, $base-font-size, $limit-font-size) {
	@include calcScalableFont($context-width, $base-font-size, $limit-font-size, down);
}




// DEMOS:
.u-scalable-1 {
	@include scaleFont(77.5rem, 4rem, 1.875rem, 6.250rem);
}

.u-scalable-2 {
	@include scaleFontUp(77.5rem, 3rem, 3.75rem);
}

.u-scalable-3 {
	@include scaleFontDown(77.5rem, 3rem, 1.125rem);
}

.u-scalable-4 {
	@include scaleFontDown(77.5rem, 1.375rem, 1rem);
}

            
          
!
999px
Loading ..................

Console