What steps can I take to avoid my Bootstrap Alert overlapping items in my Nav bar when displayed?

Here is the code from my _notices.html.erb file:

<% flash.each do |msg_type, message| %>
<div class="row pt-6 alert-messages">
  <div class="col-lg-6 offset-lg-3">
      <div id="inner-message" class="alert <%= bootstrap_class_for(msg_type) %>">
        <div class="container">
          <button class="close" data-dismiss="alert"><span>×</span></button>
          <%= message %>
        </div>
      </div>
    </div>
  </div>
<% end %>

The corresponding CSS for this code snippet is as follows:

#inner-message {
  margin: 0 auto;
}

.alert-messages {
  position: fixed;
  top: 20px;
  left: 0;
  right: 0;
  z-index: 7000;
}

However, once the alert is active on the screen, the elements behind the .alert-messages div become unclickable, as shown in the screenshot below.

https://i.sstatic.net/VwcGe.png

I'm looking for a solution to make my Bootstrap alert div float above all other elements on the screen without blocking them or making them unclickable. How can I achieve this without pushing everything else down?

Edit 1

Based on the suggestion by @symphonic, this is the updated result.

https://i.sstatic.net/SXh8T.png

Answer №1

Revise this:

<div class="row pt-6 alert-messages">
 <div class="col-lg-6 offset-lg-3">
  <div id="inner-message" class="alert <%= bootstrap_class_for(msg_type) %>">
   <div class="container">
    <button class="close" data-dismiss="alert"><span>×</span></button>
     <%= message %>
    </div>
   </div>
 </div>
</div>

Transform it to this:

<div id="inner-message" class="alert-messages alert <%= bootstrap_class_for(msg_type) %>">
 <div class="container">
   <button class="close" data-dismiss="alert"><span>×</span></button>
   <%= message %>
 </div>
</div>

Apply the following CSS:

.alert-messages {
 position: fixed;
 top: 20px;
 z-index: 7000;
 left: 50%;
 transform: translateX(-50%);
}

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

The background image is not displaying correctly on mobile devices

I'm struggling to make the image fit the entire screen on a mobile device using the code below. Interestingly, it displays correctly on my personal computer. #topContainer { height:1048px; width: 100%; padding: 0; margin: 0; } #div1 { ...

What is preventing my div from reaching 100% height when I implement an HTML5 doctype? Is there a solution to achieving a full height div?

I'm currently working on organizing the layout for a basic gallery webapp, and I've encountered an issue where some of my divs are shrinking in height when using an HTML5 doctype declaration. Despite trying different CSS properties, I can't ...

Rearrange divs from left to right on mobile display

I need help creating a header bar with three elements as shown below https://i.sstatic.net/4njuk.png When viewed on mobile, I want the menu (toggle-icon) to shift left and the logo to be centered. I attempted using push and pull with no success. Is there ...

Tips for adjusting column positions in a table while maintaining a fixed header and utilizing both horizontal and vertical scrolling

Is there a way to display a table that scrolls both horizontally and vertically, with the header moving horizontally but not vertically while the body moves in both directions? I have been able to shift the position of the columns, however, I am struggling ...

attempting to shift course, but finding no success

I'm attempting to include dir=rtl or direction: rtl in the CSS, but it doesn't seem to have any effect on the browser and the content still displays left to right. What steps can I take to fix this? This template is pre-made from Colorlib. It&ap ...

What could be causing my search form to fail to perform the search initially?

Isn't it strange that my search form doesn't work correctly the first time? You have to search again for it to function properly. Is there something wrong with my code? Fiddle HTML <form id='sform' action="/admin/search.php" metho ...

What steps can I take to fix the Error with webpack's style hot loader JavaScript?

Just starting out with native script and encountered an issue when running this code: <template> <view class="container"> <text class="text-color-primary">My Vue Native Apps</text> </view> </template> &l ...

Using Tailwind CSS to center a NexJS <Image /> component within a modal

In an effort to style my MapBoxGL popup content, I am working on aligning the text above the image to the left and centering the image below within the popup. As shown in the image below, this is currently proving to be a challenge as I transition from usi ...

Issue with Bootstrap4 styling for Django forms

I've encountered some challenges when trying to style a form in Django using Bootstrap. I've experimented with different methods but haven't been successful. Does anyone have suggestions on how to style this form using Bootstrap 4? Below i ...

The website is not optimized for mobile viewing

I have recently made an existing website responsive using Twitter Bootstrap. Everything seemed to work fine when I tested it by resizing the browser window, as it perfectly fit in the viewport. However, upon checking the site on mobile and tablet devices, ...

Deselect a checkbox that is already selected and choose the current option in the multiselect dropdown

I've created a code that allows for single select in a multiselect dropdown, disabling other options once one is chosen. However, I don't want to disable the checkboxes and would like to uncheck the selected option if a new one is chosen, all whi ...

Order of flexbox items when placed within separate divs?

Looking to rearrange the order of items using flexbox, but hitting a roadblock because one of the items I want to reorder is in a different div and not a direct child of the same parent as the other items. <div class="wrapper"> <div class="some ...

Activate the display by utilizing the getElementsByClassName method

In my design, I'd like to have the "Don't have an account?" line trigger the display of the .registrybox class when clicked. However, the script I've written doesn't seem to be working as intended. The script is meant to hide the .login ...

CSS tip: Keep the bottom of the screen always visible in an overflow window

My webpage has a continuously updating element where new data is added to the bottom. I currently have 'overflow: scroll' enabled for users to manually scroll down and view this new information. However, I am looking for a way to display these up ...

What is the best way to implement a CSS Style specifically for a glyphicon icon when it is in keyboard focus?

I have a particular icon representing a checkbox that appears as a glyphicon-star. It is designed to display in yellow when focused on by the keyboard navigation. This feature is intended to help users easily identify their location on a page. However, an ...

Ways to make JavaScript cycle through a set of images

I'm having trouble trying to set up a code that will rotate multiple images in a cycle for an image gallery I'm working on. So far, I've only been able to get one image to cycle through successfully. Any help or suggestions would be greatly ...

Manage the application of CSS media queries using JavaScript

Is there a method to control which CSS media query a browser follows using JavaScript? As an example, let's say we have the following CSS: p { color: red; } @media (max-width: 320px) { p { color: blue; } } @media (max-width: 480px) { p { col ...

Media queries for the header background image display

I am currently working on a small web project and I want to change the background image in the header section while also making it responsive. I attempted to use a class called "header_accueil" in my header to distinguish different sections of the site, bu ...

Troubleshooting: Issue with Bootstrap 4 navbar toggle button functionality

Is it possible to manually control the opening and hiding of the navbar when the toggle button is clicked in bootstrap 4? Currently, my navbar automatically opens and closes when clicking the toggle button. Any suggestions on how to modify this behavior wo ...

Aligning items vertically within a container with a constant height

I'm currently working on a website that requires a pixel-based navbar with a height of 80px. The issue I'm facing is the difficulty in vertically centering the ul and li elements. I have experimented with various methods such as using top:50%; ...