Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Question JS Resize text like an image

    Hi,
    I was wondering how to resize a div containing some text by setting a width and height so it would stretch to fill that area like an <img> tag? E.g. when you set the width and height attribute of an image, it resizes the image to fill that area. I do not wish to send a request to a php script to build an image containing the text since it will be slow and affect the scalability of the web app. Oh, and I would preferably not like to use html5 because it is a requisite that I need compatibility with ie7+ (and firefox/chrome).

    Thanks,
    akrylic

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,929
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Have a look at:-

    http://www.dynamicdrive.com/dynamici...extresizer.htm


    It is your responsibility to die() if necessary….. - PHP Manual

  • #3
    New Coder
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    0
    Thanked 3 Times in 3 Posts
    Hi,
    That looks interesting but I need to be able to specify an arbitrary width and height and have the text "stretched" to fill that space, so that is not quite what I'm looking for.

  • #4
    Regular Coder
    Join Date
    Sep 2010
    Location
    Far far away
    Posts
    122
    Thanks
    0
    Thanked 16 Times in 16 Posts
    Quote Originally Posted by akrylic View Post
    ... how to resize a div containing some text by setting a width and height ...
    Thinking that all you need is modify width or height properties of an element:
    Code:
    var el = document.getElementById(...);
    el.style.width = ... + 'px';
    el.style.height = ... + 'px';

  • #5
    New Coder
    Join Date
    Oct 2010
    Posts
    12
    Thanks
    0
    Thanked 3 Times in 3 Posts
    This will resize the div itself, but the text will stay the same size. I need to stretch the text (even if it ends up looking horrible) to fit some dimensions. If you have an image that is say 600 by 400 pixels and have an img tag with a width of 100px and a height of 100px, then the image is stretched to fit the 100x100px position that is provided.

  • #6
    Regular Coder
    Join Date
    Sep 2010
    Location
    Far far away
    Posts
    122
    Thanks
    0
    Thanked 16 Times in 16 Posts
    el.style.fontSize


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •