New ways to style Links in NextJs 13

I am relatively new to Next.js and I am attempting to create a menu with a hover effect using the following code:


import Link from 'next/link';

const MenuItem = ({ href, label }) => (
  <Link href={href} className="menu-item">
    {label}
  </Link>
);

function MainNavigation() {

  return (
    <>
      <style jsx>{`
      .header {      
        height: 5rem;
        display: flex;
        align-items: center;
        justify-content: space-between;
        background-color: #ffffff;
        padding: 0 10%;
        font-family: system-ui, sans;
        font-size: 2.5rem;
        font-weight: 800;
      }

      .logo {
        font-size: 2rem;
        color: white;
        font-weight: bold;
      }

      .header ul {
        list-style: none;
        margin: 0;
        padding: 0;
        display: flex;
        align-items: baseline;
      }

      .header li {
        margin-left: 3rem;
      }
      
      .menu-item {
        color: #000;
        position: relative;
        text-decoration: none;
      }

      .menu-item::before {
        background: hsl(45 100% 70%);
        content: "";
        inset: 0;
        position: absolute;
        transform: scaleX(0);
        transform-origin: right;
        transition: transform 0.5s ease-in-out;
        z-index: -1;
      }
  
      .menu-item:hover::before {
        transform: scaleX(1);
        transform-origin: left;
      }
    `}</style>

      <header className='header'>
        <div className='logo'>React Meetups</div>
        <nav>
          <ul>
            <li>
              <MenuItem href='/' label='menu item 1' />            
            </li>
            <li>
              <MenuItem href='/' label='menu item 2' />
            </li>
          </ul>
        </nav>
      </header>
    </>
  );
}

export default MainNavigation;

According to the latest Next.js 13 documentation, we no longer need to include the anchor tag in the Link component. However, I am having trouble applying the hover effect to my menu item. The styles are not being applied as expected.

Could someone please review this code and provide feedback on what might be the issue?

Thank you!

Answer №1

Experiment with this in your unique way

.header > nav > ul > li > a:hover{
/*insert your own CSS code*/
}

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

Display the MaterialUi snackbar using a specific process

I'm interested in displaying a message using material.ui by only calling a method and not adding a component to the parent component (similar to toastify.js). I tried an example like the one below, but I'm having trouble calling the showSnack() m ...

Troubleshooting a jQuery Selector Issue with a Dynamic Form

I developed a jQuery function to search for all the necessary inputs in a specific section of a website. function check_property_vars() { jQuery(this).parents('.property_group').find('div[id^="property_group_"]:input[required]:visible&a ...

Having trouble launching the react-native app on the Android emulator as 'C:/User/firstname' is not being identified as an internal or external command

When I run 'npx react-native start' on one terminal and wait for it to start the app, then run 'npx react-native run-android' on another terminal to start the app, I encounter this error. Any solutions please? I suspect that the white s ...

What steps should you follow to launch a react-native app from Android Studio while also setting the --mode= flag?

When trying to launch my RN application from Android Studio, it runs fine with react-native run-android command. However, I need to use react-native run-android --mode=stagingdebug instead of just react-native run-android. Is there a way to accomplish thi ...

Utilizing TailwindCSS in React Server Components within Next.js: A Comprehensive Guide

Exploring the capabilities of React Server Components, specifically with Next.js. Encountered an issue when changing from _app.tsx to _app.server.tsx</code - the TailwindCSS styles are not being applied (although the html renders correctly).</p> & ...

Save property using the useState hook

I am working on implementing a sorting function in the child component, where the props are passed in from the parent through an axios call. Should I: Store the prop in the child component's useState? Pass the parent's setState function as a pro ...

Tips for building a versatile fetch function that can be reused for various JSON formats within a React application

Using the fetch method in various components: fetch(url) .then(result => { if (!result.ok) { throw new Error("HTTP error " + result.status) } return result.json() }) .then(result => { ...

`When is it appropriate to utilize dispatch within an action creator function?`

I have created two functions in my ActionCreator.js file. First: export const fetchAudioForVerification = ()=>{ return fetch(baseUrl+'audio',{ // Perform Get Request } .then(response=>response.json());} Second: export const handleAudio ...

Ways to encourage children to adopt a specific trait

Let's discuss a scenario where I have a React functional component like this: const Test = (props: { children: React.ReactElement<{ slot: "content" }> }) => { return <></> } When a child is passed without a sl ...

Can you explain how to utilize a function on a client component in Next.js?

I'm a bit lost on how client components function. I am working on an image uploader project where I need to extract the userId from supabase, utilize the supabase server function, and then upload the image to supabase storage with the "userId/filename ...

Tips for effectively dividing a component's code into smaller sub-components

Within my component MyComp, there exists an extensive code that I wish to divide into 3 separate components. In envisioning the structure of MyComp, I am seeking general advice and a brief example in response: import React, { Component, Fragment } from & ...

What are some techniques for applying masking to various elements beyond just input fields within React?

I am currently developing an admin dashboard using NextJS and MaterialUI (mui), and I am facing a challenge with masking certain values, such as phone numbers, that are retrieved from the backend without any masking applied. While I have successfully impl ...

Personalized AWS Cognito: Strategies for Tailoring Input Field Designs

MY CURRENT CHALLENGE: Within my Vue application, I am utilizing the AWS authenticator for managing login and signup processes. However, customizing its style has proven to be difficult due to the structure being built with shadow DOM elements. CURRENT S ...

Google/StackExchange Menu Tab

I am interested in creating a navigation bar similar to Google's or StackExchange's new one, where it is always positioned at the top. It does not need to be fixed there, but I would like it to have links only. How can I achieve this layout with ...

CSS: "Cutting-edge" design. In what way?

I am seeking to replicate a design similar to that of Fantastical's website (https://flexibits.com/fantastical), where the edge of a screenshot extends beyond the page boundary. As the user resizes the window, more of the screenshot becomes visible. A ...

Incorporating a user ID (foreign key) into a MySQL table using NextJS and Prisma

Currently, I am in the process of developing an online recipe platform that allows users to log in and share their recipes. The technology stack I am using includes NextJS, Prisma, and MySQL DB. User authentication is handled with NextAuth and a credential ...

Tips on completing landing page animations and displaying the main page of a website by utilizing React JavaScript

https://i.stack.imgur.com/M4VgY.pngIs there a way to stop the landing page animation after 2-3 seconds and show the main page instead? Can I achieve this by using setTimeOut function in JavaScript? [ export default Loader; ...

I keep encountering the error message "Error: Missing credentials for 'PLAIN' when trying to configure a 3LO authentication with nodemailer and googleapis. What could be the issue causing

While trying to send emails from my Next.js API route using nodemailer and googleapis, the following error is being displayed: Error: Missing credentials for "PLAIN" To set it up, I followed a tutorial available at this link: In addition, I mad ...

Is it possible to dynamically load a specific div when the page loads, relying on the

I am using JQuery SlideUp and slideDown methods to toggle the visibility of panels. How can I load or display the first record's contact information as a default? Currently, it loads blank because I set the panel's display property to none: < ...

Encountering a module not found issue while implementing nodemailer, nextauth, and useState within a NextJS project

I am in the process of creating a basic web page that features a form component for users to post tweets after authentication. My current setup involves using NextAuth with nodemailer as the email provider for authentication. Everything was going smoothly ...