Download "Fit text in box" script

Demo

Put this into your <HEAD> section

Put this into your <BODY> section

How to use

You use this script by defining a <DIV> with an ID. This div should contain one <SPAN> tag which holds the text. Example:
<div id="theBox"><span>www.dhtmlgoodies.com</span></div>
<script type="text/javascript">fitTextInBox('theBox');</script>

The fitTextInBox() function will autofit the text into it's parent DIV. The arguments to this function is the ID of your DIV. The second argument is optional. Use it if you need to define a maximum height. The width of the div is set in the CSS:
  #theBox{
    width:500px;
    border:1px solid #CCC;
    color: #317082;
  }

Comments

Shawn
Thanks for this post!Works great for shrinking text that is too long, but I can't get it to work for text that is too short... when I try to enter a height limitation, instead of limiting the height of the font, it just hides it behind the next div.Is this what you mean by "the second argument is optional"? I used "height: 25px" in the style to define the height, but it's not working...thanks
Shawn at 08:24PM, 2011/05/19.
Shawn
let me rephrase...: How do I use the second argument? pls spell it out for me, as I am a total js noob:)
Shawn at 08:27PM, 2011/05/19.
gags
I want this in 480x800 resolution. Please send it to me in native javascript
gags at 08:18PM, 2013/07/09.
Rob
This is awesome! Thank you so much it's exactly what I was looking for... I am building a UI that is multi language, so far PERFECT
Rob at 02:18PM, 2014/04/24.
Martin Adámek
Thanks, fittext.js did not work correctly for me, but your solution works perfectly for me - longer texts as well as shorter texts.It just do not react to resize of window (it works just once on loading of page),so I have written this short code to run it automatically after each window resize: (it works for me)<script> function calculate_font_sizes() { fitTextInBox('login-h1'); fitTextInBox('subtittle'); } calculate_font_sizes(); window.addEventListener('resize', calculate_font_sizes);</script>I hope it can help to someone.Martin,www.adamek.cz
Martin Adámek at 09:07PM, 2014/11/24.
JamesSeems
Home Based Business Advice To Assist You To Succeed

Everyone nowadays wants to get involved with a house business, nonetheless they aren't sure of the steps they have to take to make it happen. If you feel it's intimidating, then this post is to suit your needs. The next article will show you how you can successfully operate a work from your home business.

Launching a home business are often very exciting yet it is also plenty of work. Find your niche, your neighborhood of experience, and move from there. It might be quite helpful if you pick an area that showcases your expertise. Before aggressively pursuing only one thing, do your homework. Ensure that you network at the same time with others that have created successful home businesses.

Start your work from home business while you are still employed. Whenever you can maintain your income from work, that can help, it requires a while to get started on creating any money, so. Having money in your pocket while awaiting profits to construct from the new venture is definitely advantageous.

Before beginning your do business from home business, don't quit your day job. When starting a fresh business it is best to continue working until your brand new business begins generating profit. Through an income while accumulating your new company is highly beneficial.

Get incoming payments deposited into the account immediately upon receipt. Don't wait weeks or months to deposit payments do it no less than every few days. Do not leave any checks lying around instead, be sure to deposit them. Go inside of the deposit and bank with the employee. ATM machines can make mistakes, in the event you go inside you will certainly be positive that it is going into your account.

Whenever you work from home, limit your household interruptions. This could reduce the amount of production and concentration that you may have on important work issues, so be sure you let people know while you are busy. Deal with these matters at the end of the task day. Keep children make and supervised yourself available if you have an emergency.

Keep the full-time job when you launch your home-based business. A company that simply started needs time to build profit, therefore it is best to have your current job. There are advantages to this, including developing a steady income as you wait for your organization to transform revenue.

Set up a fund that can be used in case there is emergency, in order to guarantee your business' financial security. Accomplishing this ensures there are no unexpected surprises that could damage your organization. Be careful not to utilize your emergency funds unless it can be truly a crisis, however. Replenish the fund as soon as you can.

Prior to starting, ensure your company has the capacity to turn a return. Investigate the market to ensure it is not saturated. For those who have plenty of competition, it will likely be much more difficult to make a profit. Look into the prospective revenue of your work at home business before you decide to enter one.

Usually do not think you are likely to get wealthy overnight, be sensible. Can be your product premium quality, and may customers continue being enthusiastic about it? Are you an upstanding individual who values honesty?

All the knowledge provided in the paragraphs above must have got the creative juices flowing along with the strategies commencing to develop at the back of the mind. Now you have to take this knowledge and expand upon it. Learn anything you can regarding your business interest. Do your very best to implement these ideas, and you should have a much easier time becoming successful.


https://www.instagram.com/oody_geffen/


yehuda sadok
JamesSeems at 04:45AM, 2019/06/28.

Post your comment

Don't have an avatar? Create one at Gravatar.com.

Confirmation code:

Go to cbolson.com


About/Contact | A good idea? | Submit a script | Privacy notice
© 2005 - 2019 dhtmlgoodies.com