
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
adapttext.js
Advanced tools
adapttext.js is a dependency free and simple javascript solution capable to fit your text inside the parent element.
adapttext.js is a dependency free and simple javascript solution capable to fit your text inside the parent element.
It calculates the maximum font-size possibile in order to keep the text's width and height inside the parent.
It's very useful in responsive situation and where we don't know in advance the text's length (text pulled from a CMS?). It is also very handy when we need to display text along an image and we want to avoid overlaps.
adapttext.js supports AMD, CommonJS and Browser global (it uses UMD)
You can install it using bower: bower install adapttext.js --save-dev
You can install it using npm: npm install adapttext.js --save-dev
or just including the script in your page:
<script src="adapttext.js" type="text/javascript"></script>
new AdaptText(element, options);
Example:
<div id="mybox">
<span>This is an example test...</span>
</div>
<style>
#mybox {
width: 50%;
height: 30%;
}
</style>
<script>
var el = document.getElementById('mybox');
var adapt = new AdaptText(el);
</script>
If you're using jQuery in your project you can use
$('.mybox').adaptText(options);
If you need the adapttext.js instance later:
var instance = $('.mybox').data('adaptText');
instance.destroy();
adapttext.js also accept some optional options:
new AdaptText(el, {
minFontSize: 10, //define in px the minimum font size possible
maxFontSize: 200, //define in px the maximum font size possible
tollerance: 10, //define a number of px of allowed exceed
callback: function(newpx) {
//this callback is called everytime a new font size is set
//the first argument is the new font-size px value
}
});
display: inline-block
and margin: 0
.destroy()
Removes the event listener attached to the window resize.
.elaborate()
Force the recalculation of the correct font-size.
Most solutions (flowtype.js, fitText.js...) uses jquery as dependency and just fit the text based on parent's width, without the height constraint.
adapttext.js is released under the MIT License and it's made by Luigi De Rosa.
The photo used in the demo is courtesy of https://unsplash.com/danielacuevas
Issue & Pull Requests are more than welcome!!
FAQs
adapttext.js is a dependency free and simple javascript solution capable to fit your text inside the parent element.
The npm package adapttext.js receives a total of 0 weekly downloads. As such, adapttext.js popularity was classified as not popular.
We found that adapttext.js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.