Incorporating a triangular arrow at the center of the bottom of the navigation item/menu

How can I position a white triangle at the bottom of my horizontal menus when they are hovered/activated? The triangle should be aligned to the right-most corner of the menu, not the center. Adding CSS "left: 50%;" positions it in the center of the menu bar/screen. Here is the code snippet: Html:

  <div class="navbar-collapse collapse">
                    <ul class="navbar-nav">
                        <li class="nav-item">
                            <a class="nav-link text-white">Home</a>
                        </li>
                        <li class="nav-item">
                            <a class="nav-link text-white">Privacy</a>
                        </li>
                    </ul>
                </div>

CSS:

  li.nav-item a:hover::after {
        content: "";
        height: 0;
        width: 0;
        border-left: 6px solid transparent;
        border-right: 6px solid transparent;
        border-bottom: 6px solid #fff;
        position: absolute;
     /*left:50%;*/
        bottom: 0;
    }

Update1: The image below shows that the triangle is in the bottom-right corner of "Home" instead of centered below the menu. The same happens when hovering over "Privacy". https://i.sstatic.net/tBAGx.png

Update2: Adding ".text-center" to either "li" or "a" does not solve the issue.

Thank you in advance!

Answer №1

After experimenting, I ended up utilizing the following CSS properties:

display: block; 
position: relative; 
left: 50%; 
bottom: -10px;

This adjustment was essential for getting it to function properly.

In addition, I made changes by eliminating the padding in the navbar and incorporating "pt-1" into "li".
The reason behind why display: block; made a difference remains unknown to me.

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

An effective approach to automatically close an Expansion Panel in an Angular Mat when another one is opened

I am attempting to implement functionality where one expansion panel closes when another is opened. By default, the multi attribute is set to "false" and it works perfectly when using multiple expansion panels within an accordion. However, in this case, I ...

Restrict the Three.js Raycaster to a designated section within the HTML without using offsets

As I dive into using Three.js and the Raycaster for object picking, my HTML structure consists of a Navigation Bar in the head section and the rendering area in the body section. However, I encountered an issue where there was an offset in the Raycaster d ...

unable to display loading image prior to upload

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html lang="en"> <head> <title>Unique Prints</title> <meta charset="utf-8"> <meta name="viewport" conte ...

Determining the Position of the Cursor Within a Div

When a link is clicked, a pop up is displayed. Here is the code for the pop up: <div class='' id="custom-popover"> <div class="arrow"></div> <h3 class="popover-title">Popover left</h3> <div class="pop ...

The issue is that dates submitted from jQuery are not being captured in the POST variable in

I'm currently in the process of integrating fullcalendar into my php application. However, I've encountered an issue when trying to save events to the database - specifically, the database only accepts title and url if they are enclosed in doubl ...

Initiate an animation upon reaching a designated element using Jquery scroll event

Hey there! I've been trying to create an animation without using any plugins, but unfortunately, I haven't had much luck so far. Here's the code I've been working on. If anyone can help me figure this out, I'd really appreciate it ...

Adaptable Navigation

I am currently working on creating a responsive navigation menu inspired by Bootstrap's design. However, I have encountered some challenges in implementing it. The current issue I am facing is that the navigation disappears when transitioning from a s ...

Tips for showcasing a lineup horizontally with HTML and CSS

I'm currently working on creating a menu using HTML. I've included my links in an unordered list (ul) as shown below. In my CSS, I added a display:inline; property to the links to make them appear side by side like a menu. However, for some reaso ...

Ways to determine the success of $wpdb->query and retrieve the outcome

Currently, I am in the process of developing a WordPress website, I have implemented a form that allows users to make modifications and update the database: Below is the HTML/PHP code snippet: echo '<form class="form-verifdoc" target=&q ...

Guide to centering a list on a webpage using Bootstrap 3

Looking to create a centered list using the latest version of Bootstrap 3. Any tips? The desired list should be positioned in the middle of the page. ___________________________________________ | | | ...

Nested Property Binding in CallByName

I am looking to utilize CallByName in VBA to extract specific data from various webpages with differing html structures. In my scenario, I need to reference multiple parent nodes to access an element with or tags. Here is an example of the code: The eleme ...

Printing content using JavaScript on a point of sale (POS) printer with

I need to print a specific div on my POS printer named Optimuz. I have attempted using the following code: <div id="printAreaInvoice" style="visibility: hidden;font-size:8px;width:200px;"></div> < ...

What is the best way to appropriately update a partial that displays another partial (refreshing with JavaScript leads to a page within a page)?

Update 2 - marzapower's assistance proved valuable once again. The success section in the ajax was identified as the root cause of the issue, as explained below. UPDATE: marzapower's solution works effectively (refer to it below), but I require ...

The Videojs controls are unresponsive to clicks

Having a strange issue with videojs. I've been attempting to load videojs in the same way as outlined in the documentation, using a dynamic video tag. videojs(document.getElementById('myVideo'), { "controls": true, "autoplay": false, "prelo ...

Tips for implementing SVG textPath in a div's background-image using CSS

Is it possible to implement SVG textPath in a div background-image using CSS? Check out my CodePen project here While this code works in HTML, it seems to be ineffective in CSS. background-image: url("data:image/svg+xml;charset=utf8,%3Csvg id='decor ...

Obtaining text from a select list using JQuery instead of retrieving the value

How can I retrieve the value from a select list using jQuery, as it seems to be returning the text within the options instead? Below is my simple code snippet: <select id="myselect"> <option selected="selected">All</option> <op ...

What can I do to enhance the responsiveness of this rotating cube?

Here I am working with a rotating cube on the web. Check out my similar code. I am attempting to make it so that when the browser size is reduced, the table and cube also shrink in size accordingly without changing their position relative to each other. I ...

Having trouble with jQuery ajax posting - receiving null value in alert box

My XML service is returning null responses, and I'm having trouble figuring out why. Any help in solving this issue would be greatly appreciated. When sending a username and password through the service, both correct and incorrect credentials are lea ...

Refreshing the page causes JavaScript to fail loading

Recently, I encountered a puzzling error. Upon visiting this link The carousel fails to load properly near the bottom of the page. However, if you click on the logo or navigate back to the home page, it works fine. Additionally, performing a command + r ...

What is the method for writing the following line in CSHTML server-side code?

<script> function a(id) { var table = document.getElementById(id); .... } </script> @{ //Is there a way to rewrite the line "var table = document.getElementById(id)" here within the ser ...