How to use pure CSS to achieve text break animation effect (with source)

Source: Internet
Author: User
This article brings to you the content is about how to use the pure CSS to achieve the text break animation effect (with source), there is a certain reference value, the need for friends can refer to, I hope to help you.

Effect Preview

Source code Download

Https://github.com/comehope/front-end-daily-challenges/tree/master/012-broken-text-effects

Code interpretation

Define the DOM, with only one element, the element has a Data-text attribute, and the property value equals the text within the element:

<div class= "text" data-text= "Break" >BREAK</div>

Center display:

HTML, body {    height:100%;    Display:flex;    Align-items:center;    Justify-content:center;}

To set the gradient background color:

Body {    background:linear-gradient (brown, Sandybrown);}

Set font size for text:

. text {    font-size:5em;    font-family: "Arial Black";}

Add text using pseudo-elements:

. text {    position:relative;}. Text::before,.text::after {    content:attr (data-text);    Position:absolute;    top:0;    left:0;    Color:lightyellow;}

Set the matte for the text on the left:

. text::before {    background-color:darkgreen;    Clip-path:polygon (0 0, 60% 0, 30% 100%, 0 100%);}

Set the background and matte for the text on the right:

. text::after {    background-color:darkblue;    Clip-path:polygon (60% 0, 100% 0, 100% 100%, 30% 100%);}

When the mouse is over, the text of the mask is shifted to both sides:

. text::before,.text::after {    transition:0.2s;}. Text:hover::before {left    : -0.15em;}. text:hover::after {    left:0.15em;}

Hides auxiliary elements, including the background color of original text and pseudo-elements:

. text {    color:transparent;}. Text::before {    /*background-color:darkgreen;*/}.text::after {    /*background-color:darkblue;*/}

Text on both sides adds a skew effect:

. text:hover::before {    transform:rotate ( -5deg);}. Text:hover::after {    transform:rotate (5deg);}

Fine-tune the height of text:

. text:hover::before {    top: -0.05em;}. text:hover::after {    top:0.05em;}

Done!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.