Issue with Bootstrap flash alert CSS on mobile devices is not functioning properly

I am in the process of developing a Rails application. Within my app, I utilize Bootstrap's CSS for displaying flash messages on alerts. Instead of fully incorporating Bootstrap's CSS, I only integrate styles related to alerts in order to prevent conflicts with existing CSS.

The flash message styling works perfectly on the standard desktop screen, appearing centered and fixed as shown below:

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

However, when the flash message is displayed on a mobile screen (less than 500px), it consistently appears off-centered to the left regardless of adjustments made. This issue is depicted here:

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

My confusion lies in why this discrepancy occurs. Similar to the desktop display, I aim to maintain a consistent position for the flash message on mobile screens and have it always appear in the same location.

Below is the view code responsible for rendering the flash messages:

<div id="flash-message-wrapper">
    <% flash.each do |type, message| %>
        <div class="alert <%= alert_class_for(type) %> alert-dismissible fade in">
            <button type="button" class="close" data-dismiss="alert">
                <span aria-hidden="true">&times;</span>
                <span class="sr-only">Close</span>
            </button>
            <%= message %>
     <% end %>
</div>

The CSS code corresponding to the alert messages structure is provided below:

(CSS Code Here)

Any assistance or guidance on resolving this issue would be greatly appreciated!

Answer №1

To modify the appearance of #flash-message-wrapper, use the following CSS:

#flash-message-wrapper {
  width: 600px;
  margin: 10px auto 0 auto;
}

@media (max-width: 500px) {
  #flash-message-wrapper {
    width: 300px;
    margin: 10px auto 0 auto;
  }
}

View the live example on JSFiddle. I hope this solution is helpful.

Update

If you wish to have a hover effect on your notification, include these CSS properties in your existing styles:

position: absolute;
left: 0;
right: 0;

Check out the updated version on JSFiddle.

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

My hosting provider is not allowing the Express server to serve static files

I am facing an issue where my Express.js app is serving my js file locally, but on my hosting platform, I am unable to access the js file. var express = require("express") var app = express() var path = require("path") var bodyParser = ...

Using jQuery to swap an image with a div element and then using the image as the

I have a collection of images in a div, like so: <div class="image-container"> <img width="174" height="174" src="http://mysite.com/images/portfolio/p1.jpg" class="image-style" typeof="foaf:Image"> <img width="174" height="174" src= ...

Utilizing Javascript to create interactive images in HTML

Is there a way for JavaScript to open the current image in a new WINDOW when an ONCLICK event occurs? <script> function imgWindow() { window.open("image") } </script> HTML <img src="pond1.jpg" height="150" size="150" alt="Johnson Pond" ...

Shifting the placement of a button with the help of bootstrap

Having a bit of trouble trying to adjust the position of a button inside an input field using bootstrap. The button appears centered within the form field, but I need it to be slightly shifted to the right for design consistency. https://i.stack.imgur.com ...

An empty array is being returned from a mongoose function call

I'm currently working on a project that involves fetching random values from MongoDB using mongoose and storing them in an array. However, I am facing an issue where the array appears to be empty outside the function: exports.Run = (req, res) => { ...

A guide on incorporating Bootstrap into an npm project

After successfully setting up bootstrap and its dependencies, I'm struggling to figure out the correct way to include it in my index.html file. I attempted using require("bootstrap"), however, nothing appears to be loading. Any guidance on ...

using spread operator to extract properties from API response objects

Currently undergoing a React/Next course, we recently had to retrieve data from an API that returns a list of objects containing information to populate the page. This task was accomplished using Next's getStaticProps method, passing the data to the ...

How can I retrieve the SID received in a different tab using MSAL.js?

I have successfully integrated MSAL into a client-side library, and things are going smoothly so far. My next goal is to enable Single Sign-On (SSO) by following the instructions provided in the documentation at https://learn.microsoft.com/en-us/azure/act ...

Displaying various results using a range slider

I really need some assistance in making this range slider produce multiple outputs. I've attempted a few different options, but unfortunately, I haven't been able to figure it out. My goal is to have the text "590" display as 5.9 times the value ...

In IE, the hover state of the background color and sub menu is frequently toggling

I've been struggling with this issue all week. I have a CSS dropdown menu that uses both standard lists and content boxes as sub menus. The problem lies in IE, where each LI has an anchor tag that is set to display block in order to fill the parent LI ...

Can you explain the functionality of that snippet of JavaScript code?

Can you figure out the value of r? How does it relate to Boolean operators and objects? var data = {x:123, y:456}; var r = data && data.x || 0; Update: Upon running the code snippet, I noticed that r consistently equals x. However, the reason behind thi ...

Interacting with an XML file contained within a PHP variable using jQuery

I'm pretty new to programming, so please be patient with me =] Currently, I am working on passing a string from the user to an API using PHP. The API then responds with an XML file, which I store under $response. So far, everything is running smoothl ...

Creating Interactive Modals in Bootstrap using AJAX Requests

Currently, I am utilizing codeigniter v3 along with bootstrap v3. I have a table that displays messages, and when the details button is clicked for any message in the table, a bootstrap modal pops up to show the details. In my code, I iterate through t ...

I am experiencing difficulties with my bootstrap module not loading

Could you please investigate why my module isn't loading? The module is supposed to load under the specified conditions in the third last column, but when I test the code, it doesn't work. Can you assist me in identifying what might be causing th ...

What are the best practices for setting access permissions when using Azure AD authorization flow?

I am in the process of creating a small Next.js application with the following structure: Authenticate a user via Azure AD using Next-Auth Allow the user to initiate a SQL Database Sync by clicking a button within the app with the access token obtained du ...

What steps are involved in creating a video playlist with YouTube videos?

Is there a way to create a dynamic video playlist that supports embedded YouTube videos without refreshing the page? If a user clicks on another video, I want the video to change dynamically. You can check out this for an example. Do jPlayer, Video.js, Fl ...

Unable to display material-ui icon when using a conditional ternary statement in React

I'm facing an issue where my app crashes when attempting to display a mui icon based on a certain condition. I suspect the problem lies in how I am using PriceCheckIcon within {}. Can someone provide assistance? <span style={ ...

Keeping Chart.JS Up to Date: Updating Only Fresh Data

When a button is pressed on my website, a Bootstrap modal containing a Chart.JS is called. The data for this chart is loaded via an Ajax call as shown below: function loadReports(data) { $.ajax({ type: "POST", url: "Default.aspx/getRep ...

Unable to retrieve push token for the device. Please verify the validity of your FCM configuration

Looking for a solution to the issue of obtaining a push token Error: Unable to retrieve push token for device. Ensure that your FCM configuration is correct I have integrated Expo permissions and notifications in my React Native app, but nothing seems to ...

Ways to retrieve text like innerText that functions across all web browsers

I need to retrieve the text from a Twitter Follow button, like on https://twitter.com/Google/followers Using document.getElementsByClassName("user-actions-follow-button js-follow-btn follow-button")[0].innerText correctly displays the text as: Follow ...