creating a horizontal drop-down navigation bar


I recently created a horizontal dropdown menu for my website and I have a couple of questions regarding the styling:

1. How can I incorporate a small blue triangle above the header border that would only appear on hover? Here is an example of what I'm aiming for: https://i.sstatic.net/rAjyS.png

2. I managed to add a small arrow to the right of the links in the main navigation by using a CSS class for each list element with a dropdown menu in Wordpress. However, I utilized a CSS :after pseudo-element to add a font icon to the right of those elements, but it also added the icon to the dropdown menu links which was not my intention. https://i.sstatic.net/KPxAK.png -wordpress menu structure

HTML:

 <header>
    <div id="wrap">     
        <a id="logo" href="<?php bloginfo('siteurl');?>" title="Return to Homepage" >
            <img src="<?php bloginfo('template_url');?>/images/logo.png" alt="School Logo" width="53" height="70" />
        </a>
        <h1>SCHOOL NAME</h1>
        <nav class="cf">
            <?php wp_nav_menu( array('menu' => 'Main', 'container' => none)); ?>
        </nav>
    </div>
</header>
<div id="subnav"></div>

CSS:

/*****NAVIGATION STYLES*******/
nav{
    position:absolute;
    top: 42px;
    padding-bottom:2.7em;
}

nav li {
    float: left;
    font-size: 1.2em;
}
nav li a {
    float: left;
    padding: 0 10px 0 0;
    color: white;
}

nav ul li:first-child {
    padding-left: 70px;
}

nav ul ul{
    position: absolute;
    left: -999em;
    bottom: 0em;
    min-width: 230%;
    max-width: 170%;
}

nav ul ul li{
    font-size: 0.75em;
    float: none;
    display: inline-block;
    padding-right: 10px;
}
nav ul ul li:first-child {
    padding-left: 0;
}
nav ul ul li a {
    color: #4F4F4F;
}

nav ul ul li a:hover {
    color: black;
}


.dropdown a:after {
    content: "s";
    font-family: 'Guifxv2TransportsRegular';
    color: white;
    font-size: 0.7em;
    padding: 0 0 2px 3px;
}

/* make sub-menu visible only on active links */
nav li.active > ul {
    left:0;
}

/* clearfix micro hack = http://nicolasgallagher.com/micro-clearfix-hack/ */
/* For modern browsers */
.cf:before,
.cf:after {
    content:"";
    display:table;
}

.cf:after {
    clear:both;
}

/* For IE 6/7 (trigger hasLayout) */
.cf {
    zoom:1;
}

JavaScript:

// On mouse over, remove all active classes from main menu items and add active class to current item
$('nav > ul > li > a').mouseover(function() {
    // Remove all active classes
    $('nav > ul > li').removeClass('active');
    // Add active class to current item
    $(this).parent().addClass('active');
});

Answer №1

When using Wordpress, the classes .current-menu-item and .current_page_item are automatically added to the menu if done correctly:

For example:

<?php wp_nav_menu( array('menu' => 'Main Menu' )); ?>

To style your .current_page_item with a background image using absolute positioning, you can do something like this:

.current_page_item {
    background: url(arrow.png) no repeat;
    position: absolute;
    top: -25px; // Adjust this based on your padding or margins
    left: 50%; // Play around with this percentage or use pixels
}

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

Gridview displaying varying border styles in CSS

I'm really struggling with this issue. I have a GridView and I want to ensure that the borders are consistent across all browsers. Right now, I'm experiencing different outcomes in IE, FF, and Chrome. Despite my best efforts with CSS (I'm re ...

Display the page number when printing using CSS

I am struggling to display the page number at the bottom of my printable document. I followed a source on Stack Overflow, but unfortunately, it did not work for me. My current CSS attempt to achieve this is as follows: body { text-align: justify; } /* ...

Improve the functionality of select[multiple] to allow for single-click modifications without the need for CMD/CTRL

I am attempting to modify the default functionality of a select element so that clicking once on its options changes their selected state. Essentially, I want to eliminate the confusing requirement of holding down shift/ctrl to select multiple options. I ...

Can you help me figure out how to convert checkbox inputs into a JSON array?

As a newcomer to .js, I am facing an issue with extracting responses from a .js checkboxes form and converting them into a JSON array. Here is my HTML structure: <form> <input type="checkbox" name="Question1" id="Answer1" value="Answer1" onclick ...

Eliminate specific content from within a div tag

Looking for a solution with the following HTML. <div id="textDiv"> <p> MonkeyDonkey is not a bird. Monkey is an animal. </p> </div> In this case, I am trying to delete the word "Donkey". I attempted the code below but it did no ...

What is the technique for implementing a slide animation on hover to move a div identified by the class `box`?

How can I create a div element with the class of box that already has some transitions applied to it, and also include a slide animation on hover effect for the same div? .box { background-color: red; width: 70px; height: 70px; transition-propert ...

Loading an HTML template dynamically into a pre-loaded div element

I need to dynamically load an HTML template into my index.html file. Now, I am looking to load another HTML template into the previously loaded template content. To clarify further: The index is loaded with a dashboard template, and the dashboard contains ...

Using the .load() function to import an HTML file from the directory above

I am trying to achieve the following structure: folder1 index folder2 page to load Can I dynamically load the 'page to load' in a div within the 'index' page using DIV.load()? I have attempted various paths (../folder2/page, ./, ...

Encountering issues with uploading files using ajax

Developing my own custom CMS requires me to enable file and image uploads. Despite attempting to integrate the blueimp uploader, I encountered difficulties. The goal is to transmit formData through a jquery script to interact with my CMS. In PHP code (rec ...

An error was encountered with Jquery/Ajax when trying to serialize $(var) due to a syntax error: Unrecognized expression for the

Hello everyone. I'm currently tackling a challenge in my ASP.NET Web API project, as I encountered an error in the following code snippet: function LoadGraph(text) { console.log(typeof(text)); $.ajax({ url: "/api/Graph/LoadGraph", ty ...

css: maximum width or maximum size

My website features images with a width of 720 pixels. I am looking for a way to ensure that these images are either 95% of the page's width (with a maximum width set at 95%), or 720px if the screen size is too large. This is to prevent distortion on ...

AngularJS mobile navigation menu toggle not functioning properly with the close feature

I am currently developing a simple Single Page Application (SPA) using an HTML template. The template includes a mobile navigation menu, but I am facing issues with it not closing when navigating through routes in AngularJS. Can anyone provide guidance on ...

empty area located on the right side of my HTML/CSS website

I'm struggling to figure out why a small white space appears next to my webpage. Inspecting the element shows that the body ends before the space begins, indicating the border is where it should be. As a beginner in HTML and CSS, I hope this issue wil ...

Tips for manipulating the DOM: Pushing existing elements when new ones are dynamically created with JavaScript

I have a pre-existing DOM element (let's say a div) and I am using JavaScript, specifically React, to create a new element - another div which serves as a sidebar. The goal is for the sidebar to seamlessly shift the previous element without overlappin ...

How can I retrieve the value from an input form using jQuery if it returns null?

Despite trying various methods, I have been unsuccessful in retrieving form values using jQuery and sending them in an AJAX GET request. The value keeps showing as null even after spending more than 18 hours on it. Any help would be greatly appreciated. $ ...

Guide on adjusting the darkness of a MaterialUI Avatar component image and adding text to it

I'm currently working with the Avatar component from Material UI along with Tailwind CSS. I found that by simply adding the image URL to the src, it displays the avatar successfully. <Avatar alt="Cindy Baker" src="https://mui.com/sta ...

Position CSS elements at the bottom of the webpage

I'm having trouble with my footer always being covered by dynamic content on my page. How can I adjust the CSS to make sure the footer stays at the bottom and adjusts to the size of the content? Here's the current CSS code for the footer: div ...

Organize elements by stacking them together using HTML and CSS for a tailored selection experience

Do you have a list of words that you want to arrange in columns to optimize space in an HTML file for a Django project? If you're not very familiar with web development, feel free to break it down to me like I'm 10 years old! {% extends "to ...

Exploring the Power of Merging HTML with JavaScript in Shopify

Here is a snippet of code that I am grappling with: <div id="next-shipment"></div> var date = new Date(); // today using client's timezone date.setDate(date.getDate() + 1); // move to tomorrow date.setUTCHours(11,0,0,0); // set time using ...

The navigation bar seems to be malfunctioning as it is unable to direct users

The navigation bar consists of links to HOME, ABOUT, WORK, and CONTACT. By using the href attribute, I can navigate through the page on this single page website. PROBLEM: The ABOUT link is not working. ATTEMPTS MADE: I checked for any typos but found non ...