Feint
Feint

Reputation: 47

How to animate every single letter without the text size changing

I am trying to make every single letter get bigger on hover. I got that animation but I want to get rid of the whole sentence to move. I tried using absolute positioning; it didn't work.

Here is jsfiddle.

HTML:

<div>
    <h1>
       <span id='let-1'>S</span><span id='let-2'>a</span><span id='let-3'>m</span><span id='let-4'>p</span><span id='let-5'>l</span><span id='let-6'>e</span>
       <span id='let-7'>T</span><span id='let-8'>e</span><span id='let-9'>x</span><span id='let-10'>t</span>
    </h1>
</div>

CSS:

        h1 {
            text-align: center; 
        }
        span {
            font-size: 3em;
        }
        div:hover span {
            animation: .3s letters forwards;
        }
        #let-2 {
            animation-delay: .1s;
        }
        #let-3 {
            animation-delay: .2s;
        }
        #let-4 {
            animation-delay: .3s;
        }
        #let-5 {
            animation-delay: .4s;
        }
        #let-6 {
            animation-delay: .5s;
        }
        #let-7 {
            animation-delay: .6s;
        }
        #let-8 {
            animation-delay: .7s;
        }
        #let-9 {
            animation-delay: .8s;
        }
        #let-10 {
            animation-delay: .9s;
        }
        @-webkit-keyframes letters {
            from,to {font-size: 3em;}
            50% {font-size: 4em;}
        }
        @keyframes letters {
            from,to {font-size: 3em;}
            50% {font-size: 4em;}
        }

Upvotes: 0

Views: 920

Answers (2)

just95
just95

Reputation: 1099

Instead of animating the font-size property you could animate transform: scale()

h1 {
            text-align: center;
            
        }
        span {
            font-size: 3em;
            display: inline-block;
        }
        div:hover span {
            animation: .3s letters forwards;
        }
        #let-2 {
            animation-delay: .1s;
        }
        #let-3 {
            animation-delay: .2s;
        }
        #let-4 {
            animation-delay: .3s;
        }
        #let-5 {
            animation-delay: .4s;
        }
        #let-6 {
            animation-delay: .5s;
        }
        #let-7 {
            animation-delay: .6s;
        }
        #let-8 {
            animation-delay: .7s;
        }
        #let-9 {
            animation-delay: .8s;
        }
        #let-10 {
            animation-delay: .9s;
        }
        @-webkit-keyframes letters {
            from,to {transform: scale(1);}
            50% {transform: scale(1.3);}
        }
        @keyframes letters {
            from,to {transform: scale(1);}
            50% {transform: scale(1.3);}
        }
<div>
    <h1>
        <span id='let-1'>S</span><span id='let-2'>a</span><span id='let-3'>m</span><span id='let-4'>p</span><span id='let-5'>l</span><span id='let-6'>e</span>
     <span id='let-7'>T</span><span id='let-8'>e</span><span id='let-9'>x</span><span id='let-10'>t</span>
    </h1>
</div>

Upvotes: 7

Stan
Stan

Reputation: 26511

Just add float: left on your span elements. But then you need to center the h1 by taking its width and making margin: auto.

Fiddle

Upvotes: 0

Related Questions