JSFiddle - React, Tailwind, and code Playground
HTML
<body>
<div id="parent">
<img src="http://images.wisegeek.com/bee.jpg" alt="Pszczolka"/>
<div id="what" class="sandia">
<span>
Bringing the
<em>cloud</em>,
<strong>visualization</strong>&
<strong>
<em>cutting edge technology</em>
</strong>
to the energy industry
</span>
</div>
</div>
<button type="textFit" onclick="$('#what').fitText();">textFit()</button>
</body>
CSS
html, body{
width: 100%;
height: 100%;
}
#parent{
position: relative;
top: 10%;
left: 10%;
border: 1px solid #39dd9a;
}
#parent img{
max-width: 100%;
}
.sandia{
position: absolute;
border: 1px groove black;
width: 90%;
height: 90%;
top: 5%;
left: 5%;
}
#spanBold{
font-weight: bold;
}
#spanItalic{
font-style: italic;
}
JavaScript
function sendMessage(msg){
// var Message += " " +msg;
$("#message").html(msg);
}
function toConsole(msg){
var dNow = new Date();
console.info(dNow.getHours() + ":" + dNow.getMinutes()+":" + dNow.getSeconds()+" : "+msg);
}
$(document).ready(function(){
$('#what').fitText();
$(window).resize(
function(){
sendMessage("width: "
+$("#what").width()
+"height"
+$("#what").height());
$('#what').fitText();
});
});
/*global jQuery */
/*!
* FitText.js 1.1
*
* Copyright 2011, Dave Rupert http://daverupert.com
* Released under the WTFPL license
* http://sam.zoy.org/wtfpl/
*
* Date: Thu May 05 14:23:00 2011 -0600
*/
(function( $ ){
$.fn.fitText = function( kompressor, options ) {
// Setup options
var compressor = kompressor || 1,
settings = $.extend({
'minFontSize' : Number.NEGATIVE_INFINITY,
'maxFontSize' : Number.POSITIVE_INFINITY
}, options);
return this.each(function(){
// Store the object
var $this = $(this);
// Resizer() resizes items based on the object width divided by the compressor * 10
var resizer = function () {
$this.css('font-size', Math.max(Math.min($this.width() / (compressor*10), parseFloat(settings.maxFontSize)), parseFloat(settings.minFontSize)));
};
// Call once to set.
resizer();
// Call on resize. Opera debounces their resize by default.
$(window).on('resize.fittext orientationchange.fittext', resizer);
});
};
})( jQuery );