How to animate every single letter without the text size changing

后端 未结 2 1602
醉酒成梦
醉酒成梦 2021-01-28 14:30

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 did

相关标签:
2条回答
  • 2021-01-28 14:35

    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>

    0 讨论(0)
  • 2021-01-28 14:48

    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

    0 讨论(0)
提交回复
热议问题