Tips for personalizing and adjusting the color scheme of a menu in ant design

I am currently working on a website using reactJs and ant design. However, I have encountered an issue with changing the color of a menu item when it is selected or hovered over. Here's the current menu: Menu Image I would like to change the white color to light green but haven't found a direct way to do so without using LESS.

Is there a solution to this problem? Below is the code for the layout:

import { Layout, Menu, Icon, Row, Button, Col } from 'antd';
import React, { Component } from 'react'
import { BrowserRouter as Router, Route, Link } from "react-router-dom";

const { Header, Sider, Content } = Layout;
const { SubMenu } = Menu;

class BasicLayout extends React.Component {
  state = {
    collapsed: false,
    path: this.path
  };

  toggle = () => {
    this.setState({
      collapsed: !this.state.collapsed,
    });
  };

  render() {
    return (
      <Layout>
        <Sider className='ant-menu' trigger={null} collapsible collapsed={this.state.collapsed}>
          <div className="logo" />
          <Menu className='ant-menu' mode="inline" defaultSelectedKeys={['1']}>
            <Menu.Item key="1" >
              <Link to='/'>
                <Icon type="home" />
                <span>Home</span>
              </Link>
            </Menu.Item>
            <Menu.Item key="2">
              <Link to='/about'>
                <Icon type="plus" />
                <span>About</span>
              </Link>
            </Menu.Item>
            <SubMenu key="3" title={<span><Icon type="database" /><span>Directory</span></span>}>
                <Menu.Item>
                  <Link to='/resources/living'>
                    <span>Living Resources</span>
                  </Link>
                </Menu.Item>
                <Menu.Item>
                  <Link to='/water2'>
                    <span>Non-Living Resources</span>
                  </Link>
                </Menu.Item>
                <Menu.Item>
                  <Link to='/resources/recycle'>
                    <span>Recycling Resources</span>
                  </Link>
                </Menu.Item>

                <Menu.Item>
                  <Link to='/resources/reducing'>
                    <span>Reducing Resources</span>
                  </Link>
                </Menu.Item>
                <Menu.Item>
                  <Link to='/resources'>
                    <span>General</span>
                  </Link>
                </Menu.Item>
            </SubMenu>
          </Menu>
        </Sider>
        <Layout>
          <Header style={{ background: '#fff', padding: 0 }}>
            <Icon
              className="trigger"
              type={this.state.collapsed ? 'menu-unfold' : 'menu-fold'}
              onClick={this.toggle}
            />
          </Header>
          <Content
            style={{
              margin: '24px 16px',
              padding: 24,
              background: '#fff',
              minHeight: 280,
            }}
          >
            {this.props.children}
          </Content>
        </Layout>
      </Layout>
    );
  }
}
export default BasicLayout;

Answer №1

To update your Link, switch it to NavLink and include the attribute activeClassName

<NavLink  to="/portoflio" activeClassName="your-active-class" className="link">Portoflio</NavLink>

If you want to add hover effects, you will need to utilize CSS

a.link:hover {
  /*Define any styles for when the link is hovered over*/
  background-color: yellow;
}
.your-active-class{
 /*Define any styles for when the link is active*/
 background-color: yellow;
 }

https://www.w3schools.com/cssref/sel_hover.asp

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

Is it possible to read an XML response as a stream using Ext JS?

Requesting an XML response can sometimes result in a slow completion time due to certain constraints. Despite this, the data begins returning quickly. I am wondering if it is feasible to read the response stream in Ext JS before it is fully complete. My u ...

What is the best way to initiate a change event using JavaScript?

I am attempting to enable my 4th checkbox automatically when there is a new value in the textbox (myinput). If the textbox is empty, I want to disable it. Currently, you have to tab out before the change event is triggered. Also, how can I check for an e ...

Determine if every object in the array contains a specific key value pair

I am dealing with the following JSON data: { records:{ data:{ current:{ records:{ '2years':[{a:1, b:2, flag:true}, {a:2, b:4}, ...

Explain the operation of recursive function calls in JavaScript

I’ve been working on converting the algorithm found in this Python code snippet into JavaScript. function divide(arr, depth, m) { if (complements.length <= depth) { complements.push(2 ** (depth + 2) + 1); } var complement = comple ...

show the day of the week for a specific date saved in a MongoDB database

I need to create a report showing the total number of purchases for each day in the past week, formatted like this: { "sunday":30, "monday":20, ... } Each purchase in the database is structured as follows: { _id: 603fcb ...

A guide on customizing ng-map markers by assigning colors to different categories

One of the functionalities I have allows users to see nearby locations based on their position and selected radius. These locations fall into different categories, and now I want to customize the markers' colors based on those categories. Here is a s ...

A step-by-step guide to creating a clipboard stream using guacamole-common.js

When utilizing Guacamole.client.createClipboardStream to generate a clipboard stream and sending the stream on paste event, I noticed that the remote clipboard remains empty. const customStream = client.createClipboardStream("text/plain"); cust ...

Issue with card grid layout not displaying correct spacing. See sandbox for example

(adjust the output to trigger the md breakpoint and display cards in a row) Check out this link for reference. I'm attempting to add space between each card, but it doesn't seem to be working as expected. ...

What is the specific table element compatible with Polymer3?

I stumbled upon iron-data-table (), but it relies on bower which is used in Polymer2. However, I am working with npm in Polymer3. Is there a suitable table element or an alternative solution compatible with Polymer3? ...

Utilizing Angular 2+ to effectively manipulate the HTML Document Object Model with JavaScript in order to execute scripts

I'm facing an issue with inserting a script into my Angular project that has a specific format. <script type="text/javascript" src="https://s3.tradingview.com/external-embedding/embed-widget-events.js"> { "width": "510", "height": "600", "impo ...

Updating Mongoose References

When updating the Kwizz model with the password from req.body and team ID from req.session, it currently replaces the existing teams array. However, I am looking to simply add 1 to the array instead. I have searched for a solution but couldn't find a ...

Is it possible for AJAX to access files with unique extensions?

I recently discovered some files with the extension .cst on my localhost server. I'm wondering if AJAX is capable of loading them. So, here's my question: Can AJAX load files with custom extensions? If yes, how can I achieve this? If not, is ther ...

Loop through the coefficients of a polynomial created from a string using JavaScript

Summary: Seeking a method to generate a polynomial from specified coordinates, enabling coefficient iteration and optional point evaluation I am currently developing a basic JavaScript/TypeScript algorithm for KZG commitments, which involves multiplying c ...

The W3C Validator has found a discrepancy in the index.html file, specifically at the app-root location

While attempting to validate my HTML page, I encountered the following error: Error: Element app-root not allowed as child of element body in this context. (Suppressing further errors from this subtree.) From line 4347, column 7; to line 4347, column 16 ...

Issue with Vue's v-autocomplete component not clearing the user's typed text when an item is selected from

I have implemented a vue v-autocomplete component on my page. I am unsure if the current behavior is as expected, as I cannot find similar examples demonstrating this functionality. The issue arises when a user begins typing in text and the autocomplete ...

The transparent background causes the vertical menu to malfunction on IE8

This is the first website I am working on: www.olgoya.com The issue I am facing is that all major browsers, except IE8, display the submenu even when the mouse hovers over the 'portfolio' item. Upon investigation, I found that the problem lies w ...

Create an index.html file using webpack to utilize it with the development server

Using webpack to run my Three.js application, I have the following configuration in the webpack.config file: module.exports = { entry: `${__dirname}/src/tut15.js`, output: { path: __dirname + '/dist', filename: 'index_bundle.js&a ...

React JS application experiencing issue with input fields not clearing upon submission

I'm facing an issue with uploading data to Firebase in my ReactJS project. While the data is successfully added, I also want to clear the input fields after submission. As a newcomer to React JS, I am struggling to figure out why the fields are not cl ...

The appearance of unnecessary empty spaces at the conclusion of the page

.article-image1 { height: 256px; width: 256px; } .article-image1:before { content: ''; position: absolute; height: 100%; width: 100%; top: 0; left: 0; background-image: url(http://limootoys.com/wp-content/uploads/gentleman-e150 ...

Unable to choose an input form within a CSS div

Just installed a jQuery responsive menu tab but encountering issues with selecting forms to input values. It seems like a CSS problem that I cannot identify. Please assist me in resolving this issue. Below is the HTML code snippet: <div class="contai ...