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

Ways to superimpose an image

Struggling to overlay an image over two div columns - I attempted using Z-index and experimented with various positioning properties. What am I missing? The triangle situated behind the two boxes, along with the additional text on JSFiddle, should appear ...

Implement various class versions tailored specifically for mobile browsers

While editing a Wordpress theme, I decided to include a content box within Bootstrap's <div class="well">. However, I soon encountered an issue where there was excess space in the content box on desktop view. To address this, I removed the paddi ...

Can someone help me locate the file using the inspect element feature?

Today, I encountered a small issue on my website that I wanted to fix. Although I was able to make the necessary changes using Inspect Element, I couldn't locate the file where it needed to be changed. The website in question is gesher-jds.org/giving. ...

Utilize Flexbox to arrange elements in a column direction without relying on the position property in CSS

Flexbox - align element to the right using flex-direction: column; without relying on position in CSS Hello everyone, I am looking to move my row element to the right without using positioning. This code includes flex-direction: column; and I do not have ...

Is it possible to utilize HTML as a platform for interfacing with a C/C++ program?

As I work on a new product with USB interface, I need to create a control app for it. However, my GUI programming skills are limited, so I have thought of using a local web page within the app's installation directory as the interface for the program. ...

PhP submit triggers fatal error

I am currently developing a form to add records to a database directly from the browser. However, upon submitting the form, I encountered the following error: Fatal error: Call to a member function execute() on boolean in /srv/http/career.php on line 56 ...

The functionality of the controls is not functioning properly when attempting to play a video after clicking on an image in HTML5

While working with two HTML5 videos, I encountered an issue with the play/pause functionality. Despite writing Javascript code to control this, clicking on one video's poster sometimes results in the other video playing instead. This inconsistency is ...

Excess gap detected in dual-column design

Exploring HTML once again, I'm currently working on creating a 2 column layout that doesn't rely on floats in order to maintain the natural document flow. Most solutions I've come across involve floats or tables, which I want to avoid. I als ...

Tips for safeguarding primary design elements from modifications by user-contributed styles in a text entry box

Currently utilizing Wordpress, but I believe my inquiry pertains to any platform where users are granted frontend posting capabilities. I am interested in enabling users to customize the style of their posts, specifically limited to the description area. ...

Ensure that the "select" dropdown menu remains a constant size

One section of my Android app, powered by JQuery Mobile, displays a table with a combobox. The issue arises when selecting the option with a very long text, causing the combobox to expand and show half of the table off-screen. My goal is to set the combob ...

What is the best way to access HTML attributes within a JavaScript function when working with a dynamic element?

When a user interacts with an HTML element on my website, I aim to display the attributes of that specific element in a new browser tab. An example of such an HTML element is: <a id="d0e110" onclick="GetWordFile(this.id)" attr1="attr1_value" attr2="at ...

Tips for making content vanish or remain concealed behind a see-through header during page scrolling

I made a JavaScript fiddle http://jsfiddle.net/claireC/8SUmn/ showcasing a fixed transparent header. As I scroll, the text scrolls up behind it. How can I make the text disappear or be hidden behind the transparent div when scrolling? Edit: I should also ...

Switch up div content - advertisements at the top or bottom

An issue has arisen where the ads on a website are currently being displayed at the bottom of the source code, but they should actually be visible at the top. Here is the ad placeholder code: <div id="300_250_placeholder"></div> And here is ...

Disappearance of Dom Css following implementation of jQuery Pagination in Wordpress widget

After developing a Wordpress widget for showcasing portfolios, I have successfully integrated features such as pagination, filter categories, and customizable post count per page. Everything works seamlessly with a custom PHP pagination system that I have ...

The whitespace issue stems from the div element __next-build-watcher generated by next js and usecontext

There's a notification bar at the bottom of my page that lets the user know when their email has been sent. This bar is generated using useContext in React/Next.js. To see the code, check out this Codebox link: Code However, I've noticed there ...

Expanding the Element prototype with TypeScript

Is there a corresponding TypeScript code to achieve the same functionality as the provided JavaScript snippet below? I am looking to extend the prototype of the HTML DOM element, but I'm struggling to write TypeScript code that accomplishes this with ...

Angular is unable to eliminate the focus outline from a custom checkbox created with Boostrap

Have you noticed that Angular doesn't blur out the clicked element for some strange reason? Well, I came up with a little 'fix' for it: *:focus { outline: none !important; } It's not a perfect solution because ideally every element sh ...

inefficient performance in linking function within the visual aspect

I am working on an Ionic 4 with Angular app, where I have implemented websockets in my ComponentA. In ComponentA.html: <div *ngFor="let item of myList"> <div>{{ item.name }}</div> <div>{{ calcPrice(item.price) }}</div> ...

Difficulty in displaying JavaScript function output as text

I'm currently developing a program that randomly selects and prints a function from an array list. I am facing difficulties in getting the result to print correctly. Below is the snippet of code: const hiddenElements = document.querySelectorAll( &qu ...

javascript create smooth transitions when navigating between different pages

As a newcomer to JS, I am currently working on creating a website with an introduction animation. My goal is to have this animation displayed on a separate page and once it reaches the end, automatically redirect to the next webpage. <body onload="setT ...