1.0.0 • Published 6 years ago
scale-to-show v1.0.0
Scale to Show
Make the least scale to a fixed ratio container to show all of its content.
Great for avatar text.
Install
npm install scale-to-show
yarn add scale-to-showUsage
import { scaleToShow } from "scale-to-show";
<div class="outer-container">
<div class="container">
...
</div>
</div>
scaleToShow({
target: document.getElementById('container'),
width: 80,
height: 60,
});Caveats
- the algorithm only sets the style of
width,height,transformto the container - for the optimization, user cannot set
styleto the container - for the optimization, user cannot set
margin,padding,border,min/max-width/heightto the container
Q&A
How to display the result properly?
This is just a solution/idea of my choice:
- add
transform-origin: top leftto the container - create an outer container with the same
width/heightof purpose
How to center the text?
Add the following css to the container:
display: flex;
align-items: center;
justify-content: center;
text-align: center;How to avoid long word overflowing?
Add the following css to the container:
word-break: break-word;