Issue arising with hover animation on a stable colored background

I recently created my own website and utilized this codepen

https://codepen.io/nikolamitic/pen/vpNoNq to incorporate an animation effect on my name. While it works well overall, I encountered an issue when trying to decrease the line-height of my elements without overlapping (notice the "j" and "p" characters). You can see the problem here:

h1{
    display:inline-block;
    font-family: sans-serif;
    font-size: 110px;
    letter-spacing: 3px;
    margin:0;
    line-height: 90px;
}
h1 p{margin:0;}

/*************************************************/
/************* LETTER ANIMATION HOVER ************/
/* Credits to https://codepen.io/nikolamitic/pen/vpNoNq */

.letter-anim{
    position: relative;
    color: #fff;
    background-color: #222;
    overflow: hidden;
    cursor: pointer;
}

.letter-anim .letter-anim-dynamic,
.letter-anim  .letter-anim-dynamic p {    
    display: flex;
    justify-content: left;
    align-items: center;
    position: absolute;
    top:0;
    left:0;
    right:0;
    bottom:0;
    z-index: 2;
    transition: all ease 0.7s;
}
.letter-anim  .letter-anim-dynamic{
    background-color: #fff;
    color: #222;
    overflow: hidden;
}
.letter-anim.active .letter-anim-dynamic,
.letter-anim:hover .letter-anim-dynamic {
    transform: translateX(100%);
}
.letter-anim.active  .letter-anim-dynamic p,
.letter-anim:hover .letter-anim-dynamic p {
    transform: translateX(-100%);
}
.letter-anim-static{
    font-size: 76px;
}
<h1 class="letter-anim h1-firstname">
  <span class="letter-anim-static">
    レ・ジェーン<br/>
  </span>
  <span class="letter-anim-dynamic">
    <p>Lejeune</p>
  </span>
</h1>

<br/>

<h1 class="letter-anim h1-lastname">
  <span class="letter-anim-static">
    ジョゼーフ<br/>
  </span>
  <span class="letter-anim-dynamic">
    <p>Joseph</p>
  </span>
</h1>

Thank you for your assistance!

Answer №1

    To achieve the desired effect for the css property letter-anim.letter-anim-dynamic p, simply add margin-top: -10px in your CSS code.

 <h1 class="letter-anim h1-firstname">
      <span class="letter-anim-static">
        レ・ジェーン<br/>
      </span>
      <span class="letter-anim-dynamic">
        <p>Lejeune</p>
      </span>
    </h1>

    <br/>

    <h1 class="letter-anim h1-lastname">
      <span class="letter-anim-static">
        ジョゼーフ<br/>
      </span>
      <span class="letter-anim-dynamic">
        <p>Joseph</p>
      </span>
    </h1>


    h1{
        display:inline-block;
        font-family: sans-serif;
        font-size: 110px;
        letter-spacing: 3px;
        margin:0;
        line-height: 90px;
    }
    h1 p{margin:0;}

    /*************************************************/
    /************* LETTER ANIMATION HOVER ************/
    /* Courtesy of https://codepen.io/nikolamitic/pen/vpNoNq */

    .letter-anim{
        position: relative;
        color: #fff;
        background-color: #222;
        overflow: hidden;
        cursor: pointer;
    }

    .letter-anim .letter-anim-dynamic,
    .letter-anim  .letter-anim-dynamic p {    
        display: flex;
        justify-content: left;
        align-items: center;
        position: absolute;
        top:0;
        left:0;
        right:0;
        bottom:0;
        z-index: 2;
        transition: all ease 0.7s;
      margin-top: -10px;
    }
    .letter-anim  .letter-anim-dynamic{
        background-color: #fff;
        color: #222;
        overflow: hidden;
    }
    .letter-anim.active .letter-anim-dynamic,
    .letter-anim:hover .letter-anim-dynamic {
        transform: translateX(100%);
    }
    .letter-anim.active  .letter-anim-dynamic p,
    .letter-anim:hover .letter-anim-dynamic p {
        transform: translateX(-100%);
    }
    .letter-anim-static{
        font-size: 76px;
    }

Answer №2

Upon closer examination, it appears that the h1 container is slightly undersized for the content it holds. Consider implementing a basic padding:10px to the h1 element in order to allow more breathing room within the container.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to ensure certain items are displayed on different lines?

Currently, I am working on styling an HTML list with the following properties: font-weight: bold; padding: 0px; margin: 0px; list-style-type: none; display: block; width:700px; font-size: 14px; white-space: pre-wrap; The individual cells within this list ...

struggling to adjust image dimensions using bootstrap styling

Currently, I am in the process of creating a Carousel image slider using bootstrap. However, I am facing an issue with changing the height of the images within the carousel. Whenever I try to adjust the height, it ends up affecting both the width and heigh ...

What steps should I take to ensure my Bootstrap CSS3 code is error-free and W3C validated?

My customer is requesting that I validate the HTML5 & CSS3 code using W3. I plan on incorporating Bootstrap 3.3.4 into the project, but after including it and checking at , I discovered 32 errors and 142 warnings. The W3C CSS Validator results for (C ...

How to fill HTML <select> options using the GET Method

I am looking to populate a dropdown list with values from a repository in Qlik Sense using HTML. Are there any suggestions on how to achieve this without using PHP? As a beginner in this field, I would appreciate any guidance or assistance. UPDATE: Here ...

Using Node.js and Express, the CSS does not load due to route parameters

I'm currently working on a basic website project using Node.js, Express, and the EJS template engine. I've run into an issue where my external CSS files are not loading properly on routes that contain route parameters. Here's a snippet of my ...

I am in need of a JavaScript event that will take precedence over the CSS pointer

There is an image causing issues with scrolling on a mobile device because it's located in the finger-friendly area where people tend to scroll. I attempted to use pointer-events: null; to allow scrolling, but this also prevented the click event from ...

Resizing the Logo as You Scroll

I need my logo to shrink when I activate the slideshow, similar to what is shown in the image. https://i.sstatic.net/WhobD.jpg However, I'm struggling to get the jQuery code to work. Can someone please demonstrate how I can shrink a logo, like the o ...

I am interested in creating a class that will produce functions as its instances

Looking to create a TypeScript class with instances that act as functions? More specifically, each function in the class should return an HTMLelement. Here's an example of what I'm aiming for: function generateDiv() { const div = document.crea ...

mobile screens causing bootstrap columns to overlap

The code I am working with is shown below: <div class="container"> <div class="col-md-3 calendar"> </div> <div class="col-md-9"> <button></button> (more buttons...) </div> < ...

Delaying UI interactivity until the document is fully loaded

I'm currently developing a web application that must be compatible with Internet Explorer 8 (yes, you read it right, compatible with the HELL). The issue I'm facing is with uploading a file which is later processed by PHP code and then refreshes ...

Tips for creating a responsive H1 tag within the Avada WordPress theme by implementing CSS

One of my acquaintances recently upgraded his Avada WordPress theme to the latest version of WordPress without physically uploading any files. However, after this upgrade, he noticed that the page titles (H1) no longer appear responsive as they did before. ...

The default margin of an HTML element is set to fill the width of its containing div and cannot be overridden

As a budding web developer, I'm encountering a basic issue that has me scratching my head. Any assistance would be highly appreciated: Regardless of the width I specify for elements within a particular div container, both Safari and Chrome seem to au ...

issue with fetching response from ajax post call in slim framework 3

Update: The issue has been resolved. The correct localhost address for the ajax request should have been 127.0.0.1 instead of 121.0.0.1 On my client side, I am using the following code to send a POST request to localhost/login. <html> <title> ...

Exploring the process of setting a background image within a div tag

My goal was to design a clickable box that would redirect users to "#". I initially thought about using area maps within div or p tags, but unfortunately that wouldn't work. Does anyone have any suggestions for alternative solutions? ...

Interrupt the current with an external factor

I am working with a flexbox layout that currently looks like this: https://i.stack.imgur.com/ULHEk.jpg My main question now is whether there is a way to disrupt the flow externally from the flexbox, so that the blocked element can move to the next positi ...

Variation in element widths and CSS widths

While inspecting an element in FF, it displays a width of 225px. However, the applied CSS sets the width to 207px for this element. The discrepancy may be due to Bootstrap and varying resolutions. Is there a tool available to identify chang ...

When making a request for "/example.php/" the CSS does not seem to take effect, however, the content is displayed properly

Currently, I am working on a PHP script where I have divided each section into separate .php files and included them using the include() function. Here is an example of how everything is set up in different folders: header.php footer.php etc.. When acc ...

Ensure that the div extends to the bottom of the page

I'm currently working on a web design assignment for one of my courses, and I'm facing some challenges with getting the div elements to span the entire page in terms of color. http://jsfiddle.net/vmm1s4Lt/ http://codepen.io/bmxatvman14/pen/fih ...

The navigation bar is positioned with white space above it

Currently working on a website design and facing an issue with adding a clickable button to the Nav-bar. Noticed some white-space above the Nav-bar which is not desired. I had previously posted a similar question but unable to identify the CSS error causi ...

"Challenges Arising in Deciphering a Basic JSON Array

After countless attempts, I am still struggling to solve this issue. My PHP code is functioning properly, as it returns the expected data when "Grove Bow" is selected from the dropdown menu: [{"wtype":"Grove Bow","was":"1.55","wcc":"5","wbdmin":"12","wbdm ...