The hover effect is failing to impact a child element during a transition

I created a link with an arrow next to it that should move 20px to the right when hovered over, using a transition of 1s. However, for some reason the transition is not affecting the arrow. Can anyone please assist me in figuring out why this is happening?

HTML

<a>Register now<i class="fa-solid fa-chevron-right"></i></a>

CSS

a{
  transition: padding-left 1s;
}

a:hover{
  text-decoration: underline;
}

a:hover i{
  padding-left: 20px;
}  

Answer №1

Make sure to include the transition: padding-left 1s; property in the i element, not directly in the a element. Here's how it should be structured:

a{
  transition: padding-left 1s;
}

a i {
  transition: padding-left 1s;
}

a:hover{
  text-decoration: underline;
}

a:hover i{
  padding-left: 20px;
}  
<a>Register now<i class="fa-solid fa-chevron-right"><span style="width:10px;height:10px;background:black;display:inline-block"/></i></a>

*edit: I included a span inside the i for illustration purposes, assuming the missing fa-solid fa-chevron-right styles.

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

Material-UI Swipeable Drawer with a see-through design

Any tips on how to apply a 'transparent' style background property to my SwipeableDrawer component from Material UI? I'm having difficulty changing the background directly from my code since the component generates another component in the H ...

CSS tip: Keep the bottom of the screen always visible in an overflow window

My webpage has a continuously updating element where new data is added to the bottom. I currently have 'overflow: scroll' enabled for users to manually scroll down and view this new information. However, I am looking for a way to display these up ...

When the @gridGutterWidth(s) is set to 0px for a flush grid in Bootstrap, the navbar's 'a.brand' breaks onto its

Big shoutout to the amazing StackOverflow community for helping me eradicate countless bugs before they even surfaced. Your crowd sourcing powers are truly magical. I'm in the process of building a website using the Wordpress Roots theme, which is ba ...

Creating a dynamic multi-item carousel with Materialize (CSS) cards using data from a loop - here's how!

Using a for loop, the following code generates a list of cards. These cards are intended to be displayed in a carousel with 4 cards visible at once, and a next arrow button allows users to navigate through the next set of 4 cards. Materialize cards have ...

Image background is not showing up in the input field

It seems like I've hit a roadblock with this issue. Despite my best efforts, I can't seem to find a solution. You can view the problem LIVE HERE. The banner's two input boxes should have background images displayed, but they are not showin ...

Exploring the power of nested styled components in Material UI is a great way to elevate the styling of your project

Can someone explain how to access a second styled component using '@mui/system' in order to add a hover effect to a parent element that will modify the max-height of its child? Please keep in mind that I am referring to mui's styled compone ...

What steps do I need to take in order to create a histogram with perfect symmetry?

I am looking to create a unique JavaScript program that can generate a symmetric histogram resembling the image provided below: This program will prompt the user to input the number of bars they want to display and specify the character used to draw the b ...

What is the best way to make the children of a parent div focusable without including the grandchildren divs in the focus?

I want to ensure that only the children of the main div are able to receive focus, not the grandchildren. Here is an example: <div class="parent" > <div class="child1" > <!-- should be focused--> <div class="g ...

Applying Regular Expressions in Java to "convert" a CSS style into an HTML tag style

In my Java code, I have a String variable that contains HTML code like this: <span style="text-decoration: underline;">test</span> My goal is to convert it to look like this: <u>test</u> If the HTML code is like this: <span ...

Misalignment of Font-awesome icons in the footer section

I've implemented a footer on my website. My goal is to have the icons centered both vertically and horizontally, with the colored area: Always positioned at the bottom of the screen No taller than the icons themselves Here's the code snippet: ...

the scrollbars are appearing on the window instead of within my div container

I'm having trouble getting a scrollbar on my div element when the content is too wide. Instead, the scrollbar always appears on the window itself. I have tried adjusting the overflow settings but can't seem to find the right solution. jsFiddle ...

Picking an item for alignment at the center with flexbox styling

What was the reason for specifying .footer-background to have a display: flex property in order to center the .copyright-text? Why did setting display: flex on .footer not achieve the desired result? .footer-background { background-color: #00008B; ...

Experience a login page similar to Google's with a fully functional back button

I'm currently working on a login page that requires the user to enter their username and have it validated before proceeding. Once the username is confirmed as valid, a new input field for password entry should appear. However, I'm facing an issu ...

Cannot assign border to an undefined element - JavaScript

Currently, I am attempting to validate some code using javascript. However, I am encountering a frustrating issue where I keep getting an "Uncaught TypeError: Cannot set property 'border' of undefined". Being relatively new to javascript, I ...

Aligning input and submit fields perfectly in the same line

Struggling to get an input form and submit button to align perfectly in Firefox and Safari. Any advice? Here's the current CSS for the 'Keep in touch' widget on www.landedhouses.co.uk: form.mc4wp-form p{margin-left:0px !important; display: ...

The table is too wide for its parent mat-nav-list, stretching to 100%

Here is the code snippet I am using to display a table inside a mat-nav-list: <mat-nav-list> <table> <tr>Node Information</tr> <tr> <td>Name</td> <td *ngIf="activeNod ...

Combining Blazor with Bootstrap for seamless form validation

After gaining some experience with Razor, I decided to explore Blazor. However, I encountered a familiar challenge - integrating validation with Bootstrap. The issue lies in the mismatch between Blazor's validation result classes and those of Bootstra ...

When table cells are added dynamically, they are not encompassed by the solid fixed title bar when scrolling

My webpage has a fixed title bar with a high z-index that overlaps all other elements on the page when they are scrolled up, except for the dynamically created table cells. What attributes or styles do I need to set in order to hide the table cells behin ...

Switch up the stylesheet in WordPress when an administrator is signed in

Looking for a way to incorporate conditional PHP code into my theme that will load a different stylesheet when either an admin or a specific user (ID=1) is logged in. Does WordPress have a function that can make this happen? There's a particular div ...

When coding on Github pages, the behavior of code blocks can vary depending on whether

I am interested in obtaining the offline version, which can be seen here: https://i.sstatic.net/NKFSQ.jpg On the other hand, the online version has a different appearance: https://i.sstatic.net/133gH.jpg If you want to view the incorrect version, click ...