Updating Navigation Bar Font

I am a novice in the process of constructing my own navigation bar for my website, and I am encountering difficulties when trying to customize the font (color, font-family, etc).

Currently, the links in my navigation bar (such as home, contact, store, etc) are displayed as default links. I attempted to create a new ID in my style.css file called a.nav {}, but I am unsure how to apply it to my navbar instead of the default a {}.

This is the snippet of code I have in my header.php file:

<nav class="site-nav">
  <?php
  $args = array(
  'theme_location' => 'primary'
  );
  ?>

            <?php wp_nav_menu(  $args ); ?>
          </nav>
</header>

This is the code from my style.css file:

## Links
--------------------------------------------------------------*/
a {
color:#000;
}

a:visited {
/*color:#454545;*/
}

a:hover,
a:focus,
a:active {
color: #fff;
text-decoration:bold;
}

a:focus {
outline:none;
}

a:hover,
a:active {
outline: 0;

}

/* Links - home.site-nav */
a.nav:link {
font-family: montserrat;
font-weight: 100;
font-style: normal;
color:#fff;
}

a.nav:visited {
/*color:#454545;*/
}

a.nav:hover,
a.nav:focus,
a.nav:active {
color: #fff;
text-decoration:bold;
}

a.nav:focus {
outline:none;
}

a.nav:hover,
a.nav:active {
outline: 0;

}

I am seeking assistance on how to ensure that my navigation bar utilizes the newly created a.nav class instead of the default a. Any suggestions?

Answer №1

If it were up to me, I would suggest utilizing the following CSS code:

.site-nav a { 

color:black;
font-size: 15px; 
/*etc*/

}

There's no need to create a new class for this purpose. This CSS should effectively style the links in your menu without requiring any HTML modifications.

Just keep in mind that any changes made to the style.css file may be undone whenever Wordpress or your theme updates, so make sure to maintain a backup copy of your work. (Alternatively, you could consider creating a child theme, but if you're unfamiliar with Wordpress, I'd advise against it).

Answer №2

Modifying the themes directly in the style.css file will be overwritten by future updates of the theme. It is recommended to insert your custom CSS under Customise > Additional CSS.

To understand what takes precedence in CSS, we need to remember these 4 rules (explained further here):

  1. Inline CSS (html style attribute) overrides CSS rules in the style tag and CSS file.
  2. A more specific selector has priority over a less specific one.
  3. Rules that appear later in the code will take precedence over earlier rules if their specificity is the same.
  4. A CSS rule with !important always takes precedence.

To ensure your styles have higher precedence, they should be placed within this block and its variations (hover, active...etc):

nav .site-nav a {
}

If you still don't see any changes, you can add !important next to the property. For example: color: #fff !important;.

I hope this information is helpful. Best of luck!

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

jquery to create a fading effect for individual list items

I have a group of items listed, and I would like them to smoothly fade out while the next one fades in seamlessly. Below is the code I've been working on: document.ready(function(){ var list_slideshow = $("#site_slideshow_inner_text"); ...

Obtain content from a div element using jQuery

Here is a snippet of HTML code that I am working with: <!doctype html> <html> <head> <meta charset="utf-8" /> <title>Demo</title> </head> <body> <script src="jquery.js"></script> <scri ...

Tips for maintaining the active tab in Jquery even after the page is reloaded, especially for tabs that are constantly changing

$(document).ready(function(){ $('.scroll_nav li a').click(function(){ $('li a').removeClass("active_scroll"); $(this).addClass('active_scroll'); $('ul li .btn-br_all_gun').click(function(){ ...

The art of sketching precise lines encircling a circular shape through the

What is the best way to use a for loop in JavaScript to draw lines around a circle, similar to those on a clock face? ...

Retrieve dynamic data from a website using jQuery's AJAX functionality

I am trying to retrieve the data from example.com/page.html. When I view the content of page.html using Chrome Browser, it looks like this: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> & ...

The appearance of the page varies between Ubuntu and Windows 7 when viewed on Firefox 31

This situation is completely new to me: The page I designed appears differently on Firefox 31 in Ubuntu (correct): compared to Windows 7 (wrong): I was able to replicate this issue on another Windows 7 machine using FF 31. My HTML and CSS both validate w ...

The Beauty of HTML5 UI

Among the plethora of HTML5 UI frameworks available, I stumbled upon a few that caught my eye: Kendo Wijmo jqWidgets Zebra Sencha SproutCore YUI XUI Shield UI The abundance of options has left me feeling overwhelmed. Upon exploring some of them, I notic ...

Using " " to split a name into two lines is not being recognized

My issue involves the display of tab names in two lines within multiple tabs. You can view the demonstration here. I attempted to use the \n character while setting the tab name but it was not recognized. Any suggestions on how to achieve this? Here ...

Create a basic chart using JavaScript

I am looking to replicate a specific chart using JavaScript. The red point in the chart is variable. So far, I have attempted to create it using the flot library: var d3 = [[7,7]]; $.plot("#placeholder", [{ data: d3, points: { show: true } }], { ...

Align both the image and text in the center with no space between

How can I center two blocks containing both images and text vertically and horizontally while using flexbox? I notice that when the text is longer, padding appears between the image and the text. How can I remove this padding?1 .product-teaser { width ...

Adjust the width of the button to best fit the content or label

Here we have a screenshot of HTML source code showing a button that is wider than the content it contains. The highlighted area in yellow indicates there is extra space at the right side of the button due to it being displayed on multiple lines. Is this be ...

Dynamic change in the mutation observer is not causing the callback to trigger

I have created a nested structure with two <div> elements. I am monitoring changes in the width of the inner <div>, which is set to width:auto;. Despite adjusting the width of the parent <div>, the mutation observer callback doesn't ...

How do I make the YouTube Grid Gallery player show up in a pop-up window?

I have been experimenting with the following code: <head> <script type="text/javascript" src="http://swfobject.googlecode.com/svn/trunk/swfobject/swfobject.js"></script> <script type="text/javascript"> function loadVideo(playerUrl, ...

Fraudulent emails targeting my posted ads - beware!

Operating a classifieds website where anyone can view and contact posters without needing to be a member poses certain challenges. One of the main issues I face is the abundance of scam emails being sent to users, attempting to deceive them and steal their ...

Using Ajax to fetch project data from an API

Currently immersed in a personal coding project, I'm struggling to troubleshoot my code. Essentially, I need to retrieve data from an API and display it on my HTML page. The data type is "jsonp" due to CORS errors that required this workaround for de ...

Developing HTML5 animation by utilizing sprite sheets

Struggling to create an engaging canvas animation with the image provided in the link below. Please take a look at https://i.stack.imgur.com/Pv2sI.jpg I'm attempting to run this sprite sheet image for a normal animation, but unfortunately, I seem to ...

Experiencing an error while trying to implement a node.js server-side service through AngularJS. Encountering the error message: "Error: [$injector:nomod] Module ‘angularjsNode

An error has occurred: Error: [$injector:modulerr] Failed to instantiate module angularjsNodejsTutorial due to: Error: [$injector:nomod] Module ‘angularjsNodejsTutorial’ is not available! You either misspelled the module name or forgot to load it. If r ...

Tips for effectively making REST requests from a ReactJS + Redux application?

I'm currently working on a project using ReactJS and Redux, incorporating Express and Webpack as well. I have successfully set up an API and now need to figure out how to perform CRUD operations (GET, POST, PUT, DELETE) from the client-side. Could so ...

Linked Dropdownlists Connected to a Single Dropdownlist

I am struggling to find the best way to phrase my question, but I need some help. I want to connect three dropdown lists together in a specific way. Dropdown list 2 and 3 should be disabled so the user cannot interact with them, while dropdown list 1 remai ...

Jquery allows for the toggling of multiple checkboxes

I have a group of check-boxes that I would like to toggle their content when checked. Currently, I am using jQuery to achieve this functionality, but I am searching for a way to optimize my code so that I do not need to write a separate function for each ...