Transform text to italico on hover!

Good, I have a paragraph and I want it to stay with font-style: italic; when I hover over it, what properties should I put in :hover?! I wish it was a transition of 0.3 seconds

Author: Droopy, 2017-12-23

2 answers

Has no way, first because the only pseudo-element that exists for lines is ::first-line and it will only take the first lines, according to font-style other than font-weight does not support numeric values so that a transition is made between the non-italic and the Italic .

But not all is lost

You can simulate the italics using transform and if you consider paragraphs by <p> it will be possible, a functional example:

Note: to avoid the jump effect( The such bug), just add: transform: skewX(0.001deg);

.container p {
    transform: skewX(0.001deg); /*evita o "efeito de pulo"*/
    transition: transform .3s ease-in-out;
}

.container p:hover {
    transform: skewX(-20deg);
}
<div class="container">
     <p>foo bar baz</p>

     <p>Hello World!</p>

     <p>Olá Mundo!</p>
</div>

Of course this is not italic, if you have styles in paragraphs such as borders or background they may be affected as well, to avoid this you can add <span> for each paragraph without style and do so for example:

.container p {
    background: #ccc;
    border-radius: 5px;
    margin-bottom: 5px;
    padding: 5px;
}

.container p span {
    display: inline-block;
    transform: skewX(0.001deg); /*evita o "efeito de pulo"*/
    transition: transform .3s ease-in-out;
}

.container p:hover span {
    transform: skewX(-20deg);
}
<div class="container">
     <p>
         <span>foo bar baz</span>
     </p>

     <p>
         <span>Hello World!</span>
     </p>

     <p>
         <span>Olá Mundo!</span>
     </p>
</div>

Trying to remove blurry during animation

Unfortunately the title says "trying" because it is not something 100% guaranteed, it depends a lot on the hardware and software it uses, the problem of the "blurry" effect in texts is very common in Chrome, the techniques (attempts) that exist are:

Use -webkit-font-smoothing: subpixel-antialiased;:

Should look like this:

.container p {
    transition: transform .3s ease-in-out;
    -webkit-font-smoothing: subpixel-antialiased;
}

And in the second example:

.container p span {
    display: inline-block;
    transition: transform .3s ease-in-out;
    -webkit-font-smoothing: subpixel-antialiased;
}

However on computers with generic video driver it will probably not work as expected, or it may not work not at all.

Use transform: translateZ(0) ...

This is a hack , it for some reason in Chrome helps in rendering acceleration, but from what I read in some cases it works and in others it does not, it probably depends on the user's equipment:

.container p:hover span {
    transform: translateZ(0) skewX(-20deg);
}

And in the second example:

.container p:hover span {
    transform: translateZ(0) skewX(-20deg);
}

Can try both, yet yes as I mentioned before, will probably depend on the equipment (hardware and software).


Note: @ keyframes not solves the problem of the effect blurry , what occurred in hugo's answer is that he used the larger font, if he initially used transform: skewX(0.001deg);, before the transition and put 2em the Font will look almost identical to keyframes

#comtransform {
    font-size: 2rem;
    font-weight: bold;
    color: blue;
    transform: skewX(0.001deg); /*evita o "efeito de pulo"*/
    transition: transform .3s ease-in-out;
}

#comtransform:hover {
    transform: skewX(-20deg);
}
<p id="comtransform">@keyframes</p>
 6
Author: Guilherme Nascimento, 2017-12-26 17:06:19

I did a test using @keyframes instead of transition and the result was even interesting, greatly decreased that buggizinho at the time of the text.

I made a simple example, see the result.

p#anima {
    font-size: 2em;
    font-weight: bold;
    color: red;
    transition: all 300ms;
}
p#anima:hover {
    transform: skewX(-10deg);
}

p#key{
    font-size: 1.2rem;
    font-weight: bold;
    color: blue;
}
p#key-small{
    font-size: 0.6rem;
    font-weight: bold;
    color: blue;
}
p#key-big{
    font-size: 3rem;
    font-weight: bold;
    color: blue;
}
p#key:hover, p#key-small, p#key-big {
    -webkit-animation-name: example; /* Safari 4.0 - 8.0 */
    -webkit-animation-duration: 500ms; /* Safari 4.0 - 8.0 */
    animation-name: example;
    animation-duration: 500ms;
    animation-iteration-count: 1;
    animation-fill-mode: forwards;
}
p#key:not(:hover), p#key-small:not(:hover), p#key-big:not(:hover) {
    -webkit-animation-name: rever; /* Safari 4.0 - 8.0 */
    -webkit-animation-duration: 500ms; /* Safari 4.0 - 8.0 */
    animation-name: rever;
    animation-duration: 500ms;
    animation-iteration-count: 1;
    animation-fill-mode: forwards;
}

/* Safari 4.0 - 8.0 */
@-webkit-keyframes example {
    from   {transform: skewX(-3deg);}
    to {transform: skewX(-10deg);}
}
/* Standard syntax */
@keyframes example {
    from   {transform: skewX(-3deg);}
    to {transform: skewX(-10deg);}
}

/* Safari 4.0 - 8.0 */
@-webkit-keyframes rever {
    from   {transform: skewX(-8deg);}
    to {transform: skewX(-0deg);}
}
/* Standard syntax */
@keyframes rever {
    from   {transform: skewX(-8deg);}
    to {transform: skewX(-0deg);}
}
<p id="anima">transition transform</p>

<p id="key">@keyframes</p>

<p id="key-small">@keyframes-small</p>

 <p id="key-big">@keyframes-big</p>
 1
Author: hugocsl, 2017-12-26 17:31:13