Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can CSS3 transition font size?

How can one make the font size grow bigger on mouse over? Color transitions work fine over time, but the font size switches immediately for some reason.

Sample code:

body p {      font-size: 12px;      color: #0F9;      transition:font-size 12s;      -moz-transition:font-size 12s; /* Firefox 4 */      -webkit-transition:font-size 12s; /* Safari and Chrome */      -o-transition:font-size 12s;      transition:color 12s;      -moz-transition:color 12s; /* Firefox 4 */      -webkit-transition:color 12s; /* Safari and Chrome */      -o-transition:color 12s; }   p:hover {       font-size: 40px;       color:#FC0;  } 
like image 352
Squirrl Avatar asked Feb 16 '12 12:02

Squirrl


People also ask

What is css3 transition?

CSS transitions provide a way to control animation speed when changing CSS properties. Instead of having property changes take effect immediately, you can cause the changes in a property to take place over a period of time.

How do you change the text size in CSS?

To change the size of your text with inline CSS, you have to do it with the style attribute. You type in the font-size property, and then assign it a value.

Which rule will change the font size of the element?

Ems. The em unit sets the font size relative to the font size of the parent element. So, giving text a font-size of 2em will make this text twice the size of its surrounding text. Setting font size in em units is ideal for an inclusive design.


2 Answers

The color transitions fine over time, but the font switches immediately for some dagnabbit reason.

Your font-size transition is being overwritten by your color transition.

transition: font-size 12s; /* transition is set to 'font-size 12s' */ transition: color 12s;     /* transition is set to 'color 12s' !! */ 

Instead, you must combine them all into one declaration:

transition: color 12s, font-size 12s; 

See: http://jsfiddle.net/thirtydot/6HCRs/

-webkit-transition: color 12s, font-size 12s;    -moz-transition: color 12s, font-size 12s;      -o-transition: color 12s, font-size 12s;         transition: color 12s, font-size 12s; 

(Or, just use the all keyword: transition: all 12s; - http://jsfiddle.net/thirtydot/6HCRs/1/).

like image 161
thirtydot Avatar answered Oct 11 '22 23:10

thirtydot


Try set transition for all properties:

-webkit-transition: all 0.3s ease; -moz-transition: all 0.3s ease; -o-transition: all 0.3s ease; -ms-transition: all 0.3s ease; 

it is works as well.

OR just font: transition: font 0.3s ease.

like image 34
Artur Keyan Avatar answered Oct 11 '22 22:10

Artur Keyan