Sunday, December 3, 2023
HomeVideo EditingStrategies for Making a Textual content “Wipe Fill”

Strategies for Making a Textual content “Wipe Fill”


In right this moment’s tutorial, we’ll be taught three totally different strategies for making a “wipe fill” CSS hover impact. We’ll even go one step additional and provides ourselves the flexibleness to pick the route of the animation. 

CSS Textual content Impact: Approach #1

Let’s stroll by the primary approach, by which we use a bit of additional markup to create every hyperlink’s “wipe fill” aspect.

Specify the Web page Markup

We’ll begin with a plain unordered record which is able to signify a typical web page menu. Every menu hyperlink will embody a textual content node and a span aspect. The textual content contained in the span will match the record merchandise’s textual content. We’ll give this aspect aria-hidden="true" as a result of we wish to disguise it from any accessibility gadgets. In precise reality, the one cause for its existence is to assist us construct the specified hover impact.

As a bonus, we’ll give ourselves the flexibility to set the route of the hover impact animation. We are able to go the data-animation customized attribute to the record gadgets which is able to decide the beginning place of their animation. Potential attribute values are to-left, to-bottom, and to-top. By default, the impact will seem from left to proper.

Right here’s the required markup:

1
<ul class="menu">
2
  <li>
3
    <a href="#0">
4
      About Us
5
      <span class="outer" aria-hidden="true">
6
        <span class="internal">About Us</span>
7
      </span>
8
    </a>
9
  </li>
10
  <li data-animation="to-left">
11
    <a href="#0">
12
      Tasks
13
      <span class="outer" aria-hidden="true">
14
        <span class="internal">Tasks</span>
15
      </span>
16
    </a>
17
  </li>
18
  <li data-animation="to-bottom">
19
    <a href="#0">
20
      Purchasers
21
      <span class="outer" aria-hidden="true">
22
        <span class="internal">Purchasers</span>
23
      </span>
24
    </a>
25
  </li>
26
  <li data-animation="to-top">
27
    <a href="#0">
28
      Contact
29
      <span class="outer" aria-hidden="true">
30
        <span class="internal">Contact</span>
31
      </span>
32
    </a>
33
  </li>
34
</ul>

Specify the Primary Kinds

Let’s proceed with the CSS kinds.

We’ll add a stroke to the menu hyperlinks through the use of the native text-stroke property. These days, this property has nice browser assist. Nonetheless, in case that you must assist Web Explorer or Microsoft Edge 12-14, you should utilize the text-shadow property to simulate a stroke.

When you don’t just like the stroke across the textual content, I’ve created an alternate structure which is able to append a background shade to the menu together with its hyperlinks. To allow it, simply connect the has-bg class to the menu.

The related kinds are as follows:

1
/*CUSTOM VARIABLES HERE*/
2

3
.has-bg {
4
  background: var(--stroke-color);
5
  padding: 40px 0 60px 0;
6
  margin-top: 20px;
7
}
8

9
.menu a {
10
  place: relative;
11
  show: inline-block;
12
  font-weight: daring;
13
  font-size: 60px;
14
  line-height: 1.4;
15
  overflow: hidden;
16
  shade: var(--white);
17
  -webkit-text-stroke: 1px var(--stroke-color);
18
  /*text-shadow: -1px -1px 0 var(--stroke-color), 1px -1px 0 var(--stroke-color), -1px 1px 0 var(--stroke-color), 1px 1px 0 var(--stroke-color);*/
19
}
20

21
.has-bg a {
22
  shade: var(--secondary-color);
23
  text-shadow: none;
24
}

And Now for the Animation Kinds

The outer span contained in the hyperlinks shall be completely positioned. Moreover we’ll give it a darkish cyan background shade and set its overflow property to hidden. By default, we’ll transfer it 100% of its authentic place to the left and its internal span 100% of its authentic place to the correct. Then, every time we hover over a hyperlink, we’ll take away their preliminary rework values. That easy trick will produce a fill textual content hover impact which is able to go from left to proper.

Listed here are the related kinds:

1
/*CUSTOM VARIABLES HERE*/
2

3
.menu .outer {
4
  place: absolute;
5
  prime: 0;
6
  left: 0;
7
  overflow: hidden;
8
  shade: var(--fill-color);
9
  rework: translateX(-100%);
10
}
11

12
.menu .internal {
13
  show: inline-block;
14
  rework: translateX(100%);
15
}
16

17
.menu a .outer,
18
.menu a .internal {
19
  transition: rework 0.15s cubic-bezier(0.29, 0.73, 0.74, 1.02);
20
}
21

22
.menu a:hover .outer,
23
.menu a:hover .internal {
24
  rework: none;
25
}

Specifying Course

Lastly, as mentioned within the markup part, we will customise the route of our hover impact by passing the data-animation attribute to a menu merchandise. Relying on the impact route (horizontal or vertical), we now have to outline reversed rework values for the .outer and .internal components:

1
[data-animation="to-left"] .outer {
2
  rework: translateX(100%);
3
}
4

5
[data-animation="to-left"] .internal {
6
  rework: translateX(-100%);
7
}
8

9
[data-animation="to-top"] .outer {
10
  rework: translateY(100%);
11
}
12

13
[data-animation="to-top"] .internal {
14
  rework: translateY(-100%);
15
}
16

17
[data-animation="to-bottom"] .outer {
18
  rework: translateY(-100%);
19
}
20

21
[data-animation="to-bottom"] .internal {
22
  rework: translateY(100%);
23
}

The ensuing demo:

CSS Textual content Impact: Approach #2

Let’s now study the second approach, by which we preserve our markup cleaner through the use of pseudo-elements to supply the “wipe fill”.

Specify the Web page Markup

We’ll begin once more with a plain unordered record. Every menu hyperlink will embody the data-text customized attribute. The worth of this attribute will match the textual content of the associated hyperlink.

Equally to the earlier instance, we’ll be capable to customise the beginning place of an animation through the data-animation attribute. Potential attribute values are to-left, to-bottom, and to-top. By default, the impact will seem from left to proper.

Right here’s the required markup to get us began:

1
<ul class="menu">
2
  <li>
3
    <a data-text="About Us" href="#0">About Us</a>
4
  </li>
5
  <li data-animation="to-left">
6
    <a data-text="Tasks" href="#0">Tasks</a>
7
  </li>
8
  <li data-animation="to-bottom">
9
    <a data-text="Purchasers" href="#0">Purchasers</a>
10
  </li>
11
  <li data-animation="to-top">
12
    <a data-text="Contact" href="#0">Contact</a>
13
  </li>
14
</ul>

Specify the Animation Kinds

The fundamental CSS kinds for this are the identical as within the earlier approach. For the animation, we’ll outline the ::earlier than pseudo-element of every menu hyperlink and completely place it. Its content material will come from the data-text attribute worth of the mum or dad hyperlink. Initially, its width shall be 0, however then, once we hover over the goal hyperlink, it will likely be set to 100%. Additionally, we’ll give it white-space: nowrap , so the textual content won’t ever wrap to a brand new line.

The associated kinds for this are as follows:

1
/*CUSTOM VARIABLES HERE*/
2

3
.menu a::earlier than {
4
  content material: attr(data-text);
5
  place: absolute;
6
  prime: 0;
7
  left: 0;
8
  width: 0;
9
  overflow: hidden;
10
  shade: var(--fill-color);
11
  white-space: nowrap;
12
  transition: all 0.15s cubic-bezier(0.29, 0.73, 0.74, 1.02);
13
}
14

15
.menu a:hover::earlier than {
16
  width: 100%;
17
}

Add the Hover Impact Kinds

Subsequent, we’ll add the kinds answerable for customizing the route of our hover impact. So first, we now have to verify the route of the specified animation (horizontal or vertical), then animate accordingly the width or the peak property of the goal pseudo-element. As well as, in case we’re within the “to left” or “to prime” animation, we should always swap the textual content shade values of the goal pseudo-element and its mum or dad hyperlink.

The kinds that deal with these animations are as follows:

1
/*CUSTOM VARIABLES HERE*/
2

3
.menu [data-animation="to-left"] a,
4
.menu [data-animation="to-top"] a {
5
  shade: var(--fill-color);
6
}
7

8
.menu [data-animation="to-left"] a::earlier than,
9
.menu [data-animation="to-top"] a::earlier than {
10
  shade: var(--white);
11
}
12

13
.menu [data-animation] a::earlier than {
14
  width: 100%;
15
}
16

17
.menu [data-animation="to-left"] a:hover::earlier than {
18
  width: 0;
19
}
20

21
.menu [data-animation="to-top"] a::earlier than {
22
  peak: 100%;
23
}
24

25
.menu [data-animation="to-top"] a:hover::earlier than {
26
  peak: 0;
27
}
28

29
.menu [data-animation="to-bottom"] a::earlier than {
30
  peak: 0;
31
}
32

33
.menu [data-animation="to-bottom"] a:hover::earlier than {
34
  peak: 100%;
35
}

The ensuing demo:

CSS Textual content Impact: Approach #3

This third CSS hover impact approach (which is the cleanest and quickest) takes benefit of the clip-path property.

Specify the Web page Markup

The markup shall be precisely because the second approach’s markup; there shall be an inventory with hyperlinks with the data-text attribute connected to every one. Once more, the existence of the data-animation attribute to a menu merchandise can customise the animation route which shall be from left to proper by default.

1
<ul class="menu">
2
  <li>
3
    <a data-text="About Us" href="#0">About Us</a>
4
  </li>
5
  <li data-animation="to-left">
6
    <a data-text="Tasks" href="#0">Tasks</a>
7
  </li>
8
  <li data-animation="to-bottom">
9
    <a data-text="Purchasers" href="#0">Purchasers</a>
10
  </li>
11
  <li data-animation="to-top">
12
    <a data-text="Contact" href="#0">Contact</a>
13
  </li>
14
</ul>

Specify the Animation Kinds

The kinds will appear to be the earlier instance. We’ll preserve having a completely positioned ::earlier than pseudo-element which shall be invisible by default. This time although, we can’t give it width: 0 or peak: 0, however as an alternative, we’ll make it invisible through the clip-path property. Then, on hover, we’ll animate this property and present the pseudo-element.

If you wish to be taught in larger element concerning the clip-path property and find out how to use it to realize eye-catching scroll results, take a look on the tutorials under.

Listed here are the principle kinds for this technique to work:

1
/*CUSTOM VARIABLES HERE*/
2

3
.menu a::earlier than {
4
  content material: attr(data-text);
5
  place: absolute;
6
  prime: 0;
7
  left: 0;
8
  width: 100%;
9
  peak: 100%;
10
  shade: var(--fill-color);
11
  clip-path: inset(0 100% 0 0);
12
  transition: clip-path 0.15s cubic-bezier(0.29, 0.73, 0.74, 1.02);
13
}
14

15
.menu [data-animation] a:hover::earlier than,
16
.menu a:hover::earlier than {
17
  clip-path: inset(0);
18
}
19

20
/* ANIMATIONS
21
–––––––––––––––––––––––––––––––––––––––––––––––––– */
22
.menu [data-animation="to-left"] a::earlier than {
23
  clip-path: inset(0 0 0 100%);
24
}
25

26
.menu [data-animation="to-top"] a::earlier than {
27
  clip-path: inset(100% 0 0 0);
28
}
29

30
.menu [data-animation="to-bottom"] a::earlier than {
31
  clip-path: inset(0 0 100% 0);
32
}

The related demo:

Conclusion

And, we’re performed! On this train, we mentioned three other ways for making a CSS-only wipe-fill hover impact. Hopefully, these have impressed you to construct one thing comparable, or no less than, incorporate the impact in an current venture.

As all the time, thanks for studying!

Be taught CSS With These Tasks

Few issues are as enjoyable on the planet of entrance finish coding as messing round with CSS; check out these CSS initiatives on Tuts+ and be taught whereas enjoying!

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments