Upon page load, CSS transitions that apply to the entire navigation menu are activated

I am currently working on designing a navigation menu for one of my websites. My idea was to create a hover effect that would make each menu item stand out when the user interacts with it, providing them with a clear focus.

However, I noticed that once the page loads, this transition occurs on all the navigation menu items simultaneously, creating a somewhat unsettling experience and impacting the overall vibe of the website.

Here is the relevant CSS code:


<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-css lang-css prettyprint-override"><code>html,
body {
  margin: 0;
  padding: 0;
  background-image: linear-gradient(to right, #2cac8c, #84a98c);
}

nav {
  position: fixed;
  top: 0;
  width: 100%;
}
nav, nav li {
  display: inline-flex;
  background-color: rgb(48, 48, 48); 
  flex-direction: row;
  font-family: 'Open Sans', sans-serif;
  font-weight: 800;
  font-size: 24px;
  text-align: right;
  color: white;
}

nav li {
  margin-left: 20px;
  margin-right: 20px;
  transition: font-size 0.5s;
}

nav li:hover {
  font-size: 30px;
}

nav ul a {
  text-decoration: none;
  color: white;
}

#name {
  display: inline-flex;
  font-size: 50px;
  color: white;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: bold;
  margin-left: 20px;
  margin-right: 1100px;
  text-align: center
}
<nav>
    <ul>
        <li id="name">Bqre</li>
        <li><a href="#about">About Me</a></li>
        <li>Web Design</li>
        <li>Resume</li>
        <li>Contact</li>
    </ul>
</nav>

Answer №1

Changing the font-size will cause the container to adjust its size automatically, resulting in a change across your entire navigation. Have you considered using transform : scale() instead? Check out this example on CodePen for reference

html,
body {
  margin: 0;
  padding: 0;
  background-image: linear-gradient(to right, #2cac8c, #84a98c);
}

nav {
  position: fixed;
  top: 0;
  width: 100%;
}
nav, nav li {
  display: inline-flex;
  background-color: rgb(48, 48, 48); 
  flex-direction: row;
  font-family: 'Open Sans', sans-serif;
  font-weight: 800;
  font-size: 24px;
  text-align: right;
  color: white;
}

nav li {
  margin-left: 20px;
  margin-right: 20px;
  transition: transform 0.5s;
}

nav li:hover {
  transform: scale(1.2);
}

nav ul a {
  text-decoration: none;
  color: white;
}

#name {
  display: inline-flex;
  font-size: 50px;
  color: white;
  font-family: Arial, Helvetica, sans-serif;
  font-weight: bold;
  margin-left: 20px;
  margin-right: 1100px;
  text-align: center
}
<nav style='width:100%'>
    <ul>
        <li id="name">Bqre</li>
        <li><a href="#about">About Me</a></li>
        <li>Web Design</li>
        <li>Resume</li>
        <li>Contact</li>
    </ul>
</nav

If I misunderstood your problem, please let me know.

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

Using CSS to apply hidden box shadow to nth child element

I am encountering a challenge with using the CSS selector :nth-child(...) in combination with the box-shadow effect. The intended outcome is as follows: The even-numbered div elements within a specific container should have alternating background colors. ...

Converting background-position: % to Tailwind: A step-by-step guide

Struggling to translate background-position: 0% 20%; into Tailwind classes I can only locate bg-{side} classes Any assistance would be greatly appreciated ...

Body Zoom Browser

My website features buttons for zooming in and out, labeled as A + and A-. I wanted to make sure that the entire body of the website could be magnified easily. That's why I came up with this code: <html> <body> <style> .cont ...

Enhancing this testimonial slider with captivating animations

I have designed a testimonial slider with CSS3 and now I am looking to enhance it by adding some animation using Jquery. However, I am not sure how to integrate Jquery with this slider or which plugins would work best for this purpose. Can anyone provide g ...

Using double quotes when adding HTML5 local storage entries

Currently, I am setting the value of a field to a variable like this: newUser = document.getElementById('userName').value; Then putting that variable into local storage: localStorage.setItem('userName', JSON.stringify(newUser)); Fet ...

What measures can be taken to prevent content from collapsing?

My goal is to create a navigation system using Bootstrap 4's collapse feature to display content based on buttons at the top of the page. Here is my navigation bar setup: <div class="port-item p-4 bg-primary" data-toggle="collapse" data-target="# ...

Issue with Aligning the Navbar in Codeigniter

I need help adjusting the position of my Navbar Components/buttons to the right. Can someone show me how to do it? Thank you in advance! Here is the code I used from a YouTube channel: <body> <nav class="navbar navbar-inverse" id="header"> ...

I'm attempting to incorporate the CSS file into the main HTML template, but the styling isn't being applied. My goal is to define the styles externally

The CSS style isn't being properly imported. Below is the base HTML file (base.html) I'm using: <!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <meta name="viewport" content="widt ...

Issue: "Download unsuccessful - File not found" message received while attempting to download a file from an application hosted on Heroku

I created a basic application using Flask that works perfectly on my local host. The homepage of the app allows users to download PDF files from a link, but when I attempt to do the same on the deployed app on Heroku, it displays an error message saying "F ...

Registration form input field in ReactJS keeps losing focus with every keystroke

Currently, I am in the process of creating a registration form for a website. I have implemented the handleChange function to alter the input text in the regData state. However, I am encountering an issue where every time I type something into an input fie ...

What is the best way to reduce the size of a Bootstrap card image back to its original dimensions when

I am currently experimenting with a bootstrap card using HTML, CSS, and Bootstrap. My main focus right now is on how to shrink the image when hovering over it. The .card-header-img has a fixed height of 150px that I do not want to modify. What I want to a ...

The concept of Modal being undefined

Upon opening my page, I am attempting to create a modal dialog that displays an image. Strangely, I keep receiving an error stating the image is undefined when trying to display it without using the onclick function. I am working with a modified version of ...

Style selector for dynamic drop-down menus

import React, { Component } from "react"; export default class FontChanger extends Component{ constructor(props){ super(props); this.state ={ selectedFont: "", currentFont: "", }; this.handleFon ...

Using CSS3 to target the final <li> element within the main list in a nested <ul> structure

I have a complex list structure: <ul> <li>Item</li> <li>Item</li> <li>Item</li> <li> <ul> <li>Nested Item</li> <li>Nested Item</li> <li>L ...

The iframe remains unresponsive and fails to resize as needed

I am facing an issue while trying to embed an iframe into one of my websites. It seems that the responsiveness is lost and it does not scale properly on mobile devices. You can see the issue here. Interestingly, when I place the same iframe on a plain HTM ...

The issue with displaying the file name in the Bootstrap 4 file input field is currently not resolved

Issue with file display in Bootstrap 4 custom-file-input class. Here is the code being used: <div class="input-group mb-3"> <div class="custom-file"> <input type="file" class="custom-file-input" id="inputGroupFile02"> <labe ...

What is the best way to incorporate index from a JSX map into a CSS file?

One challenge I am facing is reusing an n dropdown input element in various parts of different applications. This dropdown input element contains options with dropdowns nested within it, and the number of dropdowns can vary. For example: https://i.sstatic ...

Bootstrap 5: Position the cards in close vertical alignment with one another

For my latest project, I have been working on creating a responsive card collection using Bootstrap 5 and Vue 3. By utilizing the container and row classes, I was able to ensure that all cards are aligned at the same level. However, in order to keep the ti ...

Having issues with the Page inspector and viewing in browser feature in VS2012?

I'm a beginner in the world of website development and I'm facing issues with viewing my webpage on a browser. Every time I attempt to open the page inspector or choose "view in browser," I encounter the following error messages: Page Inspector ...

Enhance the appearance of a row on the table with a lumin

Is there a way to create a glowing effect around a single row in a table, similar to the style shown in this example? Here's the code that can help achieve this effect, sourced from CSS/HTML: Create a glowing border around an Input Field .glowing-bo ...