How to use pure CSS to achieve the text effect of foil ripped (with code)

Source: Internet
Author: User
This article brings you the content is about how to use pure CSS to achieve the text effect of foil ripped (with code), 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

Code interpretation

Defines the DOM, which contains a number of child elements, each of which contains one letter:

<div class= "text" >    <span>A</span>    <span>W</span>    <span>e</ span>    <span>S</span>    <span>O</span>    <span>M</span>    < Span>e</span></div>

Define Container Dimensions:

body {  margin:0;  HEIGHT:100VH;}. text {  width:100%;  height:100%;}

To set how child elements are laid out:

. text {  Display:flex;  Justify-content:space-between;}. Text span {    width:100%;}

Define Text styles:

. text span {    color:darkslategray;    Background-color:rgb (127, 141);    Font-family:serif;    Font-size:12vmin;    text-shadow:1px 1px 1px white;    Display:flex;    Align-items:center;    Justify-content:center;}

Sets the gradient of the background of the text, with the odd-digit text and the even-bit text in the opposite direction:

. Text Span:nth-child (odd) {    background:linear-gradient (to        Bottom,        rgba (127,, 141, 0.2) 0,         RGBA (127, 141, 0) 33%,         rgba (127,, 141, 0.7) 66%,         rgba (127,, 141, 0.2) 100%    );}. Text Span:nth-child (even) {    background:linear-gradient (to        top,        rgba (127, 141, 0.2) 0,         Rgba (127, 141, 0) 33%,         rgba (127,, 141, 0.7) 66%,         rgba (127,, 141, 0.2) 100%    );}

Add a divider between the text and the 1th text without dividing lines:

. text span {    position:relative;}. Text Span:not (: first-child):: Before {    content: ';    Position:absolute;    width:10px;    height:90%;    Background-color:black;    Left: -5px;    border-left:1px solid white;    border-radius:50%;}

Let the divider line up and down:

. Text Span:not (: first-child): Nth-child (Odd):: before {    top:2%;}. Text Span:not (: first-child): Nth-child (even):: before {    bottom:2%;}

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.