Replacing menu styling with JavaScript using C#

I'm currently working on a C# project to develop a smartphone-friendly website for motorists to easily pay their parking fees. However, I'm facing some challenges with the menu design. My goal is to have a white menu with black text, where the current page should be highlighted in blue with white text. Unfortunately, when I attempt to implement this using CSS, the result is not as expected - the selected page appears with white background and black text, with a hint of blue behind it. Can anyone provide guidance on how to resolve this issue?

The menu items are placed within the master page:

<div id="menu">
    <ul>
         <li id="accountmenu"><a href="PersoonlijkeGegevens.aspx">Mijn account</a></li>
         <li id="parkeermenu"><a href="Parkeer.aspx">Parkeer</a></li>
         <li id="saldomenu"><a href="SaldoGegevens.aspx">Mijn saldo</a></li>
    </ul>
</div>

I assign the "current page" class using JavaScript on each individual page:

<script type="text/javascript">
    $(document).ready(function () {
        $("#saldomenu").addClass("currentpage");
    });
</script>

Finally, I define the CSS styles in a separate file linked to the master page:

#menu ul li a:link, a:visited
{    
    background:#fff;
    display:inline-block;
    padding:5px 10px 6px;
    color:#000;
    font-size:16px;
    text-decoration:none;
    -moz-border-radius:6px;
    -webkit-border-radius:6px;
    -moz-box-shadow:0 1px 3px rgba(0,0,0,0.6);
    -webkit-box-shadow:0 1px 3px rgba(0,0,0,0.6);
    border-bottom:1px solid rgba(0,0,0,0.25);
    position:relative;
    cursor:pointer;
}

.currentpage
{
    background:#172c7d;
    color:#fff;    
}

I've been struggling to find the right solution for this issue for about two weeks now. Any assistance or insight would be greatly appreciated.

Answer №1

To ensure the desired styling is applied, you should make the currentpage class more precise. At the moment, your currentpage class is only impacting the li element and not the link within it.

#menu ul li.currentpage a:link, #menu ul li.currentpage a:visited
{
    background:#172c7d;
    color:#fff;    
}

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

Implement a menu that can be scrolled through, but disable the ability to scroll on the body of the website

When viewed on a small screen, my website transforms its menu into a hamburger button. Clicking the button toggles a sidebar displaying a stacked version of the menu on top of the normal website (position: fixed; z-index: 5;). This sidebar also triggers a ...

Obtaining an element from an iFrame is possible, however, attempting to trigger a click event using

Currently, I am using Selenium with C# to perform periodic searches on a website and extract updated data. The issue is that the website requires a login that cannot be shared publicly, making it impossible to provide a reproducible test case. Through the ...

Converting sections of JSON data into boolean values

Is there a way to convert certain parts of a JSON string into booleans? Here is an example of my JSON string: { "file_id": { "width": "560", "height": "270", "esc_button": "1", "overlay_close": "1", "overl ...

Receive immediate updates of the text input in real-time using the onkeydown event handler in Javascript

I attempted to display the content of the input box in a message div simultaneously, however, the output always seems to be one step behind. function showWhatsWritten(){ var tempText; tempText = document.getElementById("text").value; document.getEle ...

Issue when attempting to update the background image using d3.js in browsers other than Firefox

I am experiencing a strange error that is puzzling to me. What I have done is placed a background image (SVG file) in a div using CSS. This SVG is used to create a Sprite animation, which is functioning correctly. .runner { background: url("0804_ ...

The onclick event is malfunctioning in Chrome when dealing with data driven by SQL

<select id='city' name='city' > <?php $dbcon = mysql_connect($host, $username, $password); mysql_select_db($db_name,$dbcon) or die( "Unable to select database"); $city_query = "SELECT city,county FROM citycatalog order by city ...

The code coverage for the "rendering expectations" test in a particular component is insufficient

In order to test a specific component in my application, I am utilizing react-test-render. The test is intended to ensure that the component renders properly. Despite defining all the necessary properties for the component in the test file, the test cover ...

Serializing with the XmlSerializer using a predefined XmlRoot tag

Is there a method to include an XML Root Element or "Wrapper" in the XmlSerializer during the serialization process of an object? The desired XML output would resemble the following structure: <Groups> <Group method="ModifySubGroups" ID="123 ...

Send the contents of a `<ul>` element to the server using AJAX for form submission

Can someone assist me in submitting a serialized <ul> list through an AJAX post form request? I need help with this process. Below is my current code snippet. HTML: <form id="update_fruit_form" method="post" action="/update_fruits" accept-charse ...

Is there a way to create a JavaScript function that relies on a successful form submission?

After attempting to modify a post on Stack Overflow, I am facing issues with my JavaScript code. As a beginner, it's possible that I overlooked something in the code causing it not to work as expected. The project I'm working on involves creatin ...

Unable to generate a .Net Core developer certificate on a Mac operating system

While I can successfully compile my solution in Visual Studio, I encounter an issue when attempting to run it. The error message "HTTPS development certificate not found" appears. Upon clicking "Install and Trust," a popup with the message "dotnet dev-cer ...

Identify the activation of the "Inspect Element" feature

On Samy Kamkar's personal website at , there is a clever feature that detects when the console is opened and automatically clears the source code/console. It's a fascinating display of coding magic! https://i.stack.imgur.com/kag6U.jpg Curious t ...

Can SVN hooks be incorporated into NPM in a way that is comparable to git hooks?

I want to incorporate an npm script that performs linting and testing before executing an svn commit. If there are any failures during the linting or tests, I want the commit process to halt, similar to a git commit hook. Does anyone have any recommendat ...

How can the parameters for a cube geometry in three.js be dynamically updated?

Wondering about something here. I noticed that Three.js geometries come with 'parameter' fields associated with them. Take, for example, the box geometry shown in the image below... box Geometry parameters I attempted to update these parameters ...

Translating a C structure definition into Python

In my C/C# library, there is a function called functionName(int index, DataTypeDef data[], int count);. The definition of DataTypeDef is as follows: struct DataTypeDef { public int id; public float par1; ...

Update the displayed number on the input field as a German-formatted value whenever there is a change in the input, all while maintaining

In German decimal numbers, a decimal comma is used. When formatting, periods are also used for grouping digits. For example, the number 10000.45 would be formatted as 10.000,45. I am looking to create an input field (numeric or text) where users can input ...

How can I customize a default button in HTML to hide the selected option from the dropdown menu?

Hey there! I'm currently working on a website that needs to be bilingual, with Spanish as the default language. I want to include a dropdown button that allows users to translate the content into English. Here's what I've tried so far: ...

Emphasize the interactions within the table cells based on their corresponding column and row

I'm looking to achieve a specific interaction in my Angular Material table. I want to highlight the table cell interactions with column and row by extending the highlighting up to the column header and left to the row header. Is this something that ca ...

Contrast between C# TcpListener and Java's ServerSocket

I am currently developing a file transfer program between a PC and an Android device. However, I have encountered an issue with the PC server component. Initially, my Android app sends a connection request to the PC using the following code snippet: publ ...

Troubleshooting: Issues with locating CSS and JS files (404 error) while utilizing URL parameters within Django platform

I've designed a dashboard page that showcases various graphs. The page automatically updates the graph data every hour. You can access the page at the following URL: http://localhost/dashboard I'd like to give users the option to specify the ...