Enhancing navigation with creative hover effects

I've noticed a trendy effect on several websites and I'm curious about how it's done

For example:

When you hover over one of the navbar links, it appears as a button rather than a differently colored text link. How can I achieve this? I am also using bootstrap v5.3.0-alpha1 if that matters.

Here is a sample of my navbar:

import './App.css';
import React, { useState, useEffect } from "react";

const App = () => {
    return (
        <div className="App">
            <nav className="navbar navbar-expand-sm">
                <div className="container-fluid">
                    <button className="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarTogglerDemo01" aria-controls="navbarTogglerDemo01" aria-expanded="false" aria-label="Toggle navigation">
                        <span className="navbar-toggler-icon"></span>
                    </button>
                    
                    <a className="navbar-brand d-none d-md-block" href='/'>
                        <img src={"./logo.png"} style={{ height: '50px', width: '50px'}} alt='' />
                    </a>

                    <div className="collapse navbar-collapse text-center justify-content-center" id="navbarTogglerDemo01">
                        <div className="navbar-nav">
                            <a className="nav-link active" aria-current="page" href="/#">Home</a>
                            <a className="nav-link" href="/#">about_1</a>
                            <a className="nav-link" href="/#">about_2</a>
                            <a className="nav-link disabled" href='/'>Disabled</a>
                        </div>
                    </div>

                    <div className="btn-group">
                        <WagmiConfig client={wagmiClient}>
                            <RainbowKitProvider 
                                chains={chains} 
                                initialChain={mainnet}
                                theme={lightTheme({
                                    borderRadius: 'small'
                                })}
                            >
                                <ConnectButton accountStatus='address' chainStatus='none' showBalance={false} />
                            </RainbowKitProvider>
                        </WagmiConfig>

                        <div className="dropdown">
                            <button className="btn dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false" data-bs-auto-close="outside">
                                <i className="bi bi-three-dots"></i>
                            </button>
                            <ul className="dropdown-menu dropdown-menu-end" style={{ width: '30vw'}}>
                                <li><a className="dropdown-item" href="#">Action</a></li>
                                <li><a className="dropdown-item" href="#">Another action</a></li>
                                <li><a className="dropdown-item" href="#">Something else here</a></li>
                                {/* <li><i className={darkMode ? 'fas fa-sun' : 'fas fa-moon'}></i></li> */}
                            </ul>
                        </div>
                    </div>
                </div>
            </nav>
    );
};

export default App;
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.6.3/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.6.3/umd/react-dom.production.min.js"></script>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <meta name="theme-color" content="#000000" />
        <meta
            name="description"
            content="Web site created using create-react-app"
        />
        <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
        <!--
            manifest.json provides metadata used when your web app is installed on a
            user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
        -->
        <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
        <!--
            Notice the use of %PUBLIC_URL% in the tags above.
            It will be replaced with the URL of the `public` folder during the build.
            Only files inside the `public` folder can be referenced from the HTML.

            Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
            work correctly both with client-side routing and a non-root public URL.
            Learn how to configure a non-root public URL by running `npm run build`.
        -->
        <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="6b0904041f181f190a1b2b5e4558455b460a071b030a5a">[email protected]</a>/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5b3934342f282f293a2b7632383435281b6a756a6b7568">[email protected]</a>/font/bootstrap-icons.css">
        <title>React App</title>
    </head>
    <body>
        <noscript>You need to enable JavaScript to run this app.</noscript>
        <div id="root"></div>

        <script src="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="781a17170c0b0c0a1908384d564b564855191408101949">[email protected]</a>/dist/js/bootstrap.bundle.min.js" integrity="sha384-w76AqPfDkMBDXo30jS1Sgez6pr3x5MlQ1ZAGC+nuZB+EYdgRZgiwxhTBTkF7CXvN" crossorigin="anonymous"></script>
    </body>
</html>

Answer №1

Simply include a background-color when hovering and apply some default padding around the links.

ul {
display: flex;
list-style: none
}

li {
  margin-right: 15px;
}

a {
padding: 8px 15px;
color: #000;
text-decoration: none;
}

li:hover a {
background: #e1e1e1;
border-radius: 5px;

}
<nav>
  <ul>
    <li><a href="#">Home</a></li>
    <li><a href="#">About</a></li>
  </ul>
</nav>

Answer №2

nav ul {
list-style: none;
margin: 0;
padding: 0;
display: flex;
}

nav li {
margin-right: 20px;
}

nav a {
text-decoration: none;
color: #000;
transition: color 0.3s ease;
}

nav a:hover {
color: #fff;
background-color: #000;
}

The CSS code provided establishes the foundational styles for the navigation bar, utilizing a flexbox layout for the unordered list (ul) element and applying margin and padding adjustments to the list items (li).

Styling for the anchor (a) elements includes removing text decoration, setting the default text color to black, and incorporating a transition effect for smooth color changes upon hover.

Upon hovering over a link, the :hover styles come into play, altering the text color to white and introducing a background color of black for enhanced visual contrast. This straightforward yet impactful hover effect enhances the user experience when interacting with the navigation bar links.`

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

When utilizing the map function to render an array of objects, React encounters an error

My React application is throwing an error when using the map function. Interestingly, the code works fine in a sandbox environment. Error: ENOSPC: System limit for number of file watchers reached, watch. After creating a new React project, the error dis ...

To ensure optimal performance, it is recommended to deactivate react-transform-hmr in production environments using the `env` option within the B

Utilizing babel-cli to transpile JSX and ES6 features I recently updated my build command from "build": "node build", to "build": "babel-node build", Previously, everything was functioning properly However, upon running the build command, an error o ...

What could be causing the lack of access to the prerender.io service in this particular setup?

I am the owner of a Angular application running on an Apache server. To enable prerendering, I added <meta name="fragment" content="!" /> in the <head> section and set $locationProvider.html5Mode(true); In my Apache server's .htaccess fi ...

“Unlocking the secret to extracting color from an image in React Native”

While it may sound like a silly question, I am new to the world of React technology. I am looking to extract colors from an image - for example, when a user selects an image to upload, I want to identify all the colors used in that image. If this is possib ...

Maintain continuous visibility of horizontal scroll in Bootstrap responsive tables

When utilizing responsive bootstrap tables in a .net web application to showcase data, the issue arises when a substantial amount of information is returned. In such cases, a horizontal scroll bar appears at the bottom of the page. This forces users to s ...

Scrape data from LinkedIn search results using HtmlAgilityPack

Looking to fetch the top search result for a LinkedIn query. Check out this fiddle: https://dotnetfiddle.net/Vtwi7g Passing this link to 'html' variable: Targeting the first result : Wondering how to pass credentials for logging into Lin ...

I am interested in updating the color of the navigation bar displayed on this website

I am having some trouble with manipulating the appearance of - Specifically, I'm struggling to change the color of the black bar at the top to blue. I have scoured the CSS files and examined the HTML, but I can't seem to locate the relevant code ...

Exploring Material UI's Typography fontSize feature

After upgrading my material UI version from 3.9.4 to 4.11.0, I had to make some changes in the theme style override section to fix certain warnings: https://i.sstatic.net/GjzI9.png https://i.sstatic.net/LVHGk.png However, I encountered a challenge with ap ...

Experience seamless video playback on both mobile and web browsers with JW Player

I have integrated the JW Player for video playback on both mobile and web browsers. Currently, I have a library of 100 videos with dimensions set at 1280*700 pixels. These videos work well on web browsers and load quickly depending on internet speed. Howe ...

I'm encountering an issue with my React 18 application using TypeScript: the module './App' cannot be found

Encountering an issue while attempting to update to react 18. I'm curious if this problem is related to my file types. I am using Typescript, so do both the app and index files need to have a .tsx extension? Both the app and index files are located ...

Creating a scrollable panel using CSS is easy with a solid border and a panel element

Using Vaadin to design my front-end, I encountered an issue where adding border-style:solid to the style.css file resulted in a scrollable v-panel. How can I retain the solid style while removing the scrolling feature? Please refer to the screenshot for cl ...

Populate an HTML table with the days of the month and corresponding dates retrieved from a PostgreSQL database using JavaScript

I'm struggling to figure out how to use generate_series to populate an HTML table where the 'key' of <tr> corresponds to the days of the selected month and year using an <input type='month'>. So far, with the help I re ...

Using multiple selectors in JQuery and Javascript

I have a challenge where I need to execute different actions for specific divs. Here is the code snippet I currently have: $("#pending-cancel-1, #pending-cancel-2").click(function(){ Do something special for pending-cancel-1 and pending-cancel-2... }) ...

What sets the Name Attribute apart from the Name Token in HTML?

I was exploring the safety of using spaces in a name attribute and found varying opinions, with most agreeing that it is safe due to the Name attribute's utilization of CDATA token rather than a Name token. However, I am struggling to grasp the exact ...

Creating a unique and personalized dual-row navigation bar using Bootstrap

Currently, I am striving to achieve a "conflict free" two-row fixed-top navbar in Bootstrap 3. I am unsure if it necessitates two separate "navbars" according to the official Bootstrap definition. While I possess decent coding skills, my knowledge of the B ...

Error: Unable to process reduction on ships - function "reduce" is not functional

I created a boat visualization tool using a specific API. The API responds with a JSON that I then inject into a table. The issue: At times during the day, I observed the application would abruptly stop functioning and throw an error: Unhandled Rejection ...

What might be causing the React application to have trouble resolving the @tiptap/prosemirror-tables dependency?

For the past several days, I've been successfully using TipTap. However, a problem arises when I import four table lines at the top of my component - the entire project crashes before even using the table functionality. ERROR in ./node_modules/@tiptap ...

Executing JavaScript Code Through Links Created Dynamically

I am currently developing a website with a blog-style layout that retrieves information from a database to generate each post dynamically. After all posts are created, the header of each post will trigger an overlaid div displaying the full article for tha ...

Error in Blinking Tooltip when Hovering Skill Bubble (React and d3)

I've encountered a frustrating issue with tooltips on my website - they just won't stop blinking when I hover over the skill bubbles. I tried fixing the tooltips at a certain location, but whenever there's a bubble in that spot and I hover o ...

Having trouble with the jQuery each function's functionality

I am creating circular counters for surveys by generating a counter for each answer option. Currently, I am utilizing this "plugin": Issue: The problem lies in the plugin not fetching the text value from the <div> element and failing to draw coun ...