Upon clicking the navbar dropdown item, it shifts its position

I am currently working on setting up a navigation bar with multiple items aligned to the right side. However, I have encountered an issue where clicking on the "notification" icon causes the other icons in the navbar to move instead of remaining fixed in place.

Here is the code snippet that I am using:

HTML :

<nav class="navbar navbar-expand-lg navbar-dark bg-secondary justify-content-end">
  <ul class="navbar-nav menu-right">
    <div class="child child-right">    

      <!-- Parameters item -->
      <li class="nav-item">
        <a href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          <i class="fa fa-cog"></i>
          <span class="badge-sonar"></span>
        </a>
        <div class="dropdown-menu parametres" aria-labelledby="dropdownMenuMessage">
          <a class="dropdown-item" href="#">My profile</a>
          <a class="dropdown-item" href="#">Help</a>
          <a class="dropdown-item" href="#">Setting</a>
        </div>
      </li>

      <!-- Notifications item -->
      <li class="nav-item">
        <a href="#" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
          <i class="fa fa-bell"></i>
        </a>
        <div class="dropdown-menu notifications" aria-labelledby="dropdownMenuMessage">
          <div class="notifications-header">
            <i class="fa fa-bell"></i>
            Notifications
          </div>

          <!-- Notification content -->
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="#">
            <div class="notification-content">
              <div class="icon">
                <i class="fas fa-check text-success border border-success"></i>
              </div>
              <div class="content">
                <div class="notification-detail">Lorem ipsum dolor sit amet consectetur adipisicing elit. In totam explicabo</div>
                <div class="notification-time">
                  6 minutes ago
                </div>
              </div>
            </div>
          </a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item text-center" href="#">View all notifications</a>
        </div>

      </li>
    </div>

  </ul>
</nav>

SASS:

.navbar {
    overflow: visible;
    height: 56px;
    z-index: 9999;
}

.notifications {

    max-width: 250px;
    margin-left: -200px;
    margin-top: 5px;


    .dropdown-item {
        padding: .25rem 1rem;
    }

    .notifications-header {
        padding: 0 1rem;
    }

    .notification-content {
        display: flex;

        .icon {
            width: 40px;
            height: 40px;

            i {
                width: 35px;
                height: 35px;
                text-align: center;
                line-height: 35px;
            }
        }

        .content {
            line-height: 1.6;
            padding-left: 5px;
            width: calc(100% - 40px);

            .notification-time {
                font-size: .7rem;
                color: #828282;
            }

            .notification-detail {
                font-size: 12px;
                white-space: nowrap;
                overflow: hidden;
                text-overflow: ellipsis;
            }
        }
    }
}

.child {
    display: flex;
    flex-flow: row nowrap;
    flex-grow: 0;
    justify-content: flex-start;
    align-items: stretch;
}

.child.child-right {
    flex-grow: 1;
    justify-content: flex-end;
}

.child>li{
    padding-right: 50px;
}

To view the problem and provide assistance, you can check out the jsfiddle link here: https://jsfiddle.net/kiuega/beat2zmn/11/

Answer №1

Custom styles in navbar.scss are affecting the layout, such as making the drop-down menu use static positioning instead of absolute positioning.

To fix this issue, you can apply the following styles to your own style sheet:

.child > li {
  padding-right: 50px;
  position: relative;
}
.navbar-nav .dropdown-menu {
    position: absolute;
    float: none;
}

Answer №2

Examine the margins and padding within the child element by using the inspect element feature to identify any elements that may be causing a change in position.

Answer №3

When you activate the developer tools in your browser, take note of these specific classes within the dropdown panel: .navbar-nav .dropdown-menu

(modified by navbar.scss)

If you delete the 'position: static' code, it should function correctly.

Experiment with adjusting the top and left properties to achieve the desired positioning.

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

I'm having trouble figuring out how to remove an unexpected blank space that appears after the <li> element in a basic drop-down menu code. Can

Why is the browser (Mac Chrome + Firefox) adding extra space after my simple CSS drop-down menu where I have a hidden sub-menu? Check out the code below: <ul> <li>Option Zero</li> <li>Option One Is Longer</li> &l ...

Automatically save a dropdown menu selection

Is there a way to automatically save the data selected in a drop down list without having to click on a save button? public ActionResult SelectFeedBack(int id) { YelloAdminDbContext db = new YelloAdminDbContext(); ViewBag.FeedBack ...

Can anyone suggest a method to customize the appearance of select options in Vue.js?

https://i.sstatic.net/qNov8.png Is there a way to customize the color and font of select options? I'm referencing this link for an example: . I attempted CSS modifications but they don't seem to be taking effect. ...

Looking for assistance with aligning an image in a <td> cell that doubles as a link?

How can I center a play icon in the middle of a td cell and make the entire content clickable as a link, including the background image? I've tried various methods but can't seem to get it right without breaking the alignment. Any suggestions wou ...

Displaying data from a PHP form

I'm working on a table that is populated with data from my controller. The issue I am facing is that only the first record, in this case Sephen C. Cox, does not redirect me when I click the "add employee" button. For all other records, the button work ...

Attempting to optimize a webpage design for compatibility with Google's mobile-friendly testing tool

After much searching on the forum, this is my first post, so I kindly ask for patience! I am dealing with a 20-year-old website that urgently needs to be optimized for mobile devices. With almost 2200 pages, manual editing is out of the question, so I nee ...

Adjust the left and right margins while maintaining the vertical margin spacing

Is there a way to apply horizontal margin while inheriting vertical margin without explicitly setting margin-left and margin-right? I was hoping for something like margin: inherit 20px; to be effective. Take a look at the example here: https://jsfiddle.ne ...

"Change the value of a style setting in React to 'unset

One of the components has CSS properties such as `right` and `bottom` that are set with a classname. I tried to override these values using the `style` prop but have only been successful in setting numerical values like `10px` or `0px`, not `unset`. Wha ...

Is it possible to turn off GPU rasterization for a particular SVG element in Google Chrome?

There is a peculiar issue with the SVG graphic displayed on my webpage. On some computers, the complex linearGradient filling a Rect does not display all the Stops correctly, while on other computers it appears fine. I discovered that if I disable "GPU ra ...

Creating a series of menu image buttons with rollover effects using HTML and CSS

I am facing an issue with my navigation bar. I have 5 horizontally aligned .png buttons that I want to add rollover effects to using CSS, not Java. After trying multiple solutions, I still can't seem to get it right. None of the methods I attempted w ...

Is it possible to create varied background shades in CSS3 without relying on images?

Check out this fiddle: http://jsfiddle.net/dzAJp All the divs are styled with a light blue background color using the background-color CSS property instead of background-image. I want to darken the second div slightly by combining its current background ...

Basic PHP code converted into a JavaScript function for an onSubmit event within an HTML form

I have been trying to figure this out for hours. The goal is to submit a form only if one of the inputs matches a PHP echo. To simplify the script, it looks something like this: <head> </head> <body> <?php $A = rand(0,10); $B = r ...

endless cycle of scrolling for div tags

My goal is to incorporate a tweet scroller on I believe it uses the tweet-scroller from Unfortunately, this link seems broken as the demo is not functioning. I searched for an alternative solution and came across http://jsfiddle.net/doktormolle/4c5tt/ ...

Sorting table by priority in HTML is not functioning as expected

I am currently developing this code for a SharePoint 2010 platform. While the table can currently be sorted alphabetically, I am looking to implement a different functionality. Unfortunately, I am facing an issue with changing variables 'a' and ...

Creating two divs with equal heights in React using Material-UI at 50% each

I am currently utilizing a Material UI template within a react JS project. My goal is to create a div (or Grid in MUI) that spans 100% of its container's height, containing two nested divs (or Grids) that are each set at 50% height. If the internal c ...

Applying a Webkit Scroll Bar to a specific element on the webpage

I've been attempting to apply the Scroll Bar webkit styling to a particular element but haven't had any success. Despite searching extensively, I have come across 2 threads on Stack Overflow that do not provide a solution. Most of the available ...

HTML: Image not updating despite meta tag refresh

I am using the following HTML5 code to display an HTML page with an image (1.JPG). The setup is working correctly, but I am encountering an issue. The image at the specified path is supposed to be randomly replaced with a newer image within a certain tim ...

Tips for replacing all occurrences of a specific string in HTML while preserving JavaScript attributes

Is there a way to use RegEx to replace part of an HTML document without affecting the root element or other elements like event listeners? Consider this scenario: for (; document.body.innerHTML.indexOf(/ea/) != -1;) { document.body.innerHTML = docu ...

Is there a way for me to instruct jQuery to revert an element back to its initial value, prior to any dynamic alterations?

My question is regarding changing the content of a div using the `html()` method in JavaScript. I am currently working on implementing a "cancel" button and would like to revert the content back to its original value without having to completely reset it w ...

Using PHP to utilize logical OR or AND operators when adding a class to the global navigation's list items

I am currently working on implementing a global navigation bar using PHP on all pages. The PHP code is also being used to add a class and display the current page. The main challenge I am encountering involves selecting the parent navigation item. When on ...