Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8982211
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:31:38+00:00 2026-06-15T20:31:38+00:00

Open to using: jQuery / Javascript / PHP / CSS3 / HTML5 What I’m

  • 0

Open to using: jQuery / Javascript / PHP / CSS3 / HTML5

What I’m trying to achieve is dynamically change the font-size of a child element based on its parent div’s width & height. The parent div resizes on hover using jQuery. Now, I want the text inside it to grow & shrink along with it (imagine a zoom-in / zoom-out effect).

A little demonstration: http://jsfiddle.net/Aye4h/

The above example shows font-size changing dynamically on window resize. That shows pretty much what I’m trying to achieve, except that it will not be basing its size from the window, but from its parent div.

… Kind of like the background-size CSS3 property, except with text.

Here is some code that I found online (LINK) that I thought I could use.
The code does it for a span inside a parent #sidebar:

<script type="text/javascript">
$(document).ready(function() {
    var originalFontSize = 12;
    var sectionWidth = $('#sidebar').width();

    $('#sidebar span').each(function(){
        var spanWidth = $(this).width();
        var newFontSize = (sectionWidth/spanWidth) * originalFontSize;
        $(this).css({"font-size" : newFontSize, "line-height" : newFontSize/1.2 + "px"});
    });
});
</script>

While, here is my jQuery code for the parent DIVs :
(They are called .bubbles, and upon hover they expand in size)

$(window).bind("load", function() {

// LOAD BUBBLES
    $('.bubble').animate({
    opacity: 1,
    width: ['toggle', 'swing'],
    height: ['toggle', 'swing'],
    margin: '-75%'
  }, 400, function() {


// NOW, LOAD HOVER EFFECTS
// THIS EXPANDS BUBBLES BY 20% OF THEIR WIDTH & HEIGHT WHEN HOVERED
        $(".bubble").on('scale', function(e, s) {
            var data = $.data(this, 'size'),
                w = data.width,
                h = data.height;
            $(this).stop().animate({
                width: w * s,
                height: h * s,
                marginLeft: data.marginLeft - w * (s-1) / 2,
                marginTop: data.marginTop - h * (s-1) / 2
            });
        }).each(function() {
            var $this = $(this);
            $.data(this, 'size', {
                width: $this.width(),
                height: $this.height(),
                marginLeft: parseInt($this.css('margin-left')),
                marginTop: parseInt($this.css('margin-top'))
            });
        }).hover(function() {
            $(this).trigger('scale', [1.2])
        }, function() {
            $(this).trigger('scale', [1.0])

            });
        });

 });

LIVE DEMO : http://174.127.117.20/~interact/

Now I don’t know how to merge the two. My current code already saves the width & height of the bubble, & expands the bubble 20% from its original height & width upon hover…

Now my question is: how do I include text with this, of a child H1 element (placed inside .bubble)? I want to scale everything inside .bubble to match it when it’s resized.
I have discovered methods above, but I do not know how to implement it with my current code, since they do not exactly apply as is.

All help would be greatly appreciated, thank you so much for your time!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T20:31:39+00:00Added an answer on June 15, 2026 at 8:31 pm

    I have achieved this using CSS3 scale:

    (… assuming that a.expand contains our content to scale.)

    a.expand {
        transition:all .8s; 
        -moz-transition:all .8s; /* FIREFOX */
        -webkit-transition:all .8s; /* SAFARI and CHROME */
        -o-transition:all .8s; /* OPERA */
    
    
        color: #fff;
        text-align: center;
        font-family: Arial, sans-serif;
        font-size: 2em;
        width: 250px; /* 2x WIDTH HERE */
        height: 250px;  /* 2x HEIGHT HERE */
    
        transform: scale(0.80);
        -webkit-transform: scale(0.80);
        -moz-transform: scale(0.80);
        -o-transform: scale(0.80);
        -ms-transform: scale(0.80);
    }
    
    a.expand:hover {
        transform: scale(1);
        -webkit-transform: scale(1);
        -moz-transform: scale(1);
        -o-transform: scale(1);
        -ms-transform: scale(1);
    }
    

    I initially scale the content down to avoid the pixelation/blurry effect when over-scaling an element from their given size. The above code works perfectly.


    The solution is done entirely with CSS3.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I´m trying to open a tab using jquery, here is my code: $(#ecContenedorFolders).tabs({ tabTemplate:
I am trying to open a few links in a new window using Jquery
i'm using autocomplete from jquery... and i have this: $('#name_search').autocomplete({ source: search/name.php, open: function(){
I am using this chunk of jQuery/Javascript code on my site to open a
I am using jQuery to open a dialog window with a textarea transformed into
I am using jQuery, and wish to make certain links open in a new
How to prompt browser to display open/save dialog box using jquery?
I am creating an XML string using JQuery. I would like to open a
I have started using leaflet as an open source map, http://leaflet.cloudmade.com/ The following jQuery
I use a combination of html/php and javascript to open a new browser window

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.