animate the alignment of right-aligned text to move to the right side and realign to the left

I need help with a small menu-list that should expand when the mouse is nearby. By default, the menu is aligned to the right, but on hover, every other item shifts to the left to accommodate the increased height (check out the JSFiddle).

ul {
  font-size: 12px;
  transition: font-size ease 0.4s 0.4s;
  line-height: 12px;
  text-align: right;
  padding: 50px;  
  width: 500px;
  list-style-type: none;  
}

ul:hover {
  font-size: 24px;
}

li {
  height: 12px;
}

li a {
  display: block;
    text-decoration: none;
  transition: transform ease 0.8s;
  text-align: right;
}

.container:hover ul li:nth-child(even) a{
  transform: translateX(100%);
  text-align: left;
}
<div class="container">
  <ul>
    <li><a href="#">Some link</a></li>
    <li><a href="#">Some other link</a></li>
    <li><a href="#">another</a></li>
    <li><a href="#">this is the last ling</a></li>
  </ul>
</div>

The idea is working, but I still need to fine-tune the animation. The issue I'm facing is with aligning the items in the middle without causing them to jump to the left-aligned position before moving. I want them to start at their current location.

To tackle this problem, I believe I need a way to keep the items right-aligned and move them to the right by their width using

transform: translateX(self:width);
. However, I am struggling to implement this without JavaScript.

Answer №1

try this out!

li {
  height: var(--menu-lineheight);
  margin-right: 50%;
  display: flex;
  justify-content: flex-end;
}

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

Tips for positioning two fields side by side on a webpage with CSS

I currently have two datepickers aligned vertically and I'm looking to display them in a horizontal layout with some spacing between them. What changes do I need to make in order to present these two calendar pickers side by side on the same row? Cou ...

What is the method to alter the color of the browse button?

I am currently utilizing a custom file input feature from Bootstrap: https://i.sstatic.net/ybCYl.png Is there a way to modify the color of the "Browse" button? My attempts so far: Added a color tag to custom-file-input Added a color tag to custom-file- ...

Designing the appearance of a jQuery UI range slider

I recently delved into the world of jQuery UI for the first time, and let me tell you, it's been quite the challenge. I've been attempting to create a slider that looks like this: https://i.sstatic.net/YZ3gM.png However, I'm struggling to c ...

Tips for changing the color of shapes when hovering over an image state

I have arranged three images in a column and applied column-count: 3; along with setting border-width for those images. Now I am curious about how to create the hover state for these images. Here is the HTML code snippet: <div class="wrap"> < ...

Utilizing CSS to target the ID of an anchor element

I am a beginner in the world of HTML and CSS. I recently attempted to target an element using an id selector in my CSS code, but unfortunately, it did not work as expected. Can someone shed some light on why this might be happening? <!DOCTYPE html> ...

Prevent the navigation bar text from being truncated

The below code snippet: <div data-role="navbar"> <ul> <li><a href="#page_1" data-transition="none">Heading 1</a></li> <li><a href="#page_2" class="ui-btn-active ui-state-persist">Heading 2</a& ...

What strategies can be used to effectively structure CSS and JavaScript in a project for optimal organization?

In my NetBeans project, I currently have a large web project with CSS files included in the header. Some CSS codes are needed on all pages, while others are only necessary for specific pages. I am looking to optimize high-traffic pages by removing any ...

Fluid active tabs are causing alignment issues with CSS triangles

I have included CSS triangles on the active tabs with fluid width on this page, but they are not aligned properly in each tab. For example, the About Us tab is correctly and centrally aligned, but the others are too far to the right. The issue lies with t ...

Modifying the border hue of Material-UI's Select Component

Here is the Select component I've created using materials-UI <FormControl variant="outlined"> <Select value={this.state.value} onChange = {this.handleChange} className={this.props.classes.select} inputProps = {{class ...

Selenium: Error - The selector provided is not valid: The selector you have specified is invalid or illegal

My attempt at web scraping with selenium on the NFT website Magic Eden is encountering issues. While my code works without errors when scraping normal data like text from the page, it fails when I try to select an NFT category. Error Message: invalid sel ...

Center an image and superimpose text in the middle of the webpage

I am attempting to center an image with text overlay in the middle of a page. Although the image is centered correctly, the overlay text remains off-center. Below is the code snippet. The text should be positioned in the top left corner of the image. &l ...

Tips for preventing the appearance of a horizontal scroll bar when utilizing the FlexLayoutModule in Angular

import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-property-feed', templateUrl: './property-feed.component.html', styleUrls: ['./property-feed.component.scss'] }) export class Prope ...

Disappear scrollbar when overlay is activated

How can I hide the scroll bar when an overlay is displayed on my page? .overlay{ display: none; opacity:0.8; background-color:#ccc; position:fixed; width:100%; height:10 ...

Attempting to align a navigation block next to an SVG image

On my website, I envisioned a photoshopped image featuring a SVG picture of a book on the left and a "navigation block" on the right. The navigation block consists of links that redirect to other pages but it's not displaying properly. You can view th ...

Issue with transition or animation not functioning when the element is positioned prior to the toggle

Why are only the elements after the toggle working in this code snippet that animates visibility? The ones before don't seem to be affected. Any ideas on why this behavior is occurring? I'm testing this code in the latest version of Chrome. ...

Navigating through the CSS menu located in the main directory

I am facing an issue with accessing my CSS menu in different directories. In my root directory, I have a CSS menu that I want to use in subdirectories as well. However, when I navigate to a subdirectory, I find it difficult to go back to the main directory ...

What is the best way to design a bookmarklet that can overlay an HTML/div layer and apply CSS styles from an

Is there a way to incorporate a bookmarklet that can bring in a new layer/div with additional HTML and CSS from an external file, overlaying it on the current page? If anyone has an example of a bookmarklet that achieves this, would you be willing to shar ...

What is the function of object-fit when used with the canvas element?

Despite my thorough search, I have not come across any documentation to clarify this issue. Is it possible to use object-fit cover on canvas elements? My experiments have yielded unexpected results so far. Could someone provide me with a conclusive answe ...

Fieldset is not adhering to the height of its parent

I've been grappling with this issue for quite some time now, but have yet to find a satisfactory solution. Below is the code that I've been working with: CSS .parent{ width:100px; display:table; border:1px solid green; } .child{ ...

Displaying the current time and total time of a custom video player using Javascript

Currently, I'm in the process of creating an html5 video player and have incorporated javascript to update the current time as a fraction of the total time. The script I've written so far is as follows: function updateTime() { var curTime = ...