When the modal is closed, the div containing a background image and using display flex shifts positions

My layout includes a line of thumbnail images, each accompanied by an animated title that is centered using the display: flex property. The issue arises when clicking on a thumbnail to open a modal with a slideshow. Upon closing the modal, the selected gallery's thumbnail is displaced from its original position. Despite thorough CSS debugging efforts, I have been unable to identify a definitive cause. My suspicion lies with either Bootstrap modal JavaScript or a potential conflict involving the use of display: flex and display: block during hover interactions.

.gallery-top {
  height: 220px;
  margin-bottom: 10px;
  .swiper-slide {
    width: 100%;
    background-size: cover;
    background-position: center center;
    background-repeat: no-repeat;
    position: relative;
    z-index: 1;
    border-right: 3px solid #fff;
  }
}

.gallery-row {
  padding: 0 0 0 2px;
}

/* Additional CSS rules omitted for brevity */

<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet" />

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>

<div class="row gallery-row">
  <div class="col-12 col-md-6 col-lg-5ths galleryThumbs embed-responsive embed-responsive-1by1">
    <div class="embed-responsive-item galleryThumbWrapper">
      <div style="background: url('http://lorempixel.com/400/400/') no-repeat center center; background-size: cover;">
        <div class="cta_box">
          <div class="cta-content">
            /* HTML template continues */
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

/* Modal markup goes here */

For reference, you can view a fiddle of this setup here.

Answer №1

The reason for this issue is related to the styling on

@media screen and (min-width: 1024px)
. In that media query, you positioned the top of .cta_box at 100%, causing it to be pushed to the bottom. However, the bottom of the box was still set to 0 from previous styles, resulting in a height of 0 for the box and causing its content to overflow.

The movement of the background image when the modal closes is directly linked to the overflow of content within the box.

To resolve this issue, simply add overflow: hidden; to the .cta_box CSS rule.

Check out the demo here: https://jsfiddle.net/sdetcp51/54/

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

One-touch dial feature for mobile-friendly website

Currently working on a single page responsive website and looking for guidance on inserting a quick call button that will only be visible when accessed on mobile phones, while remaining hidden on desktops and tablets. Your assistance is greatly valued. Th ...

Adapting my desktop website layout to be responsive for an optimal viewing experience on iPads and mobile

I recently created a webpage for laptop view and attempted to use media queries to adjust the CSS styling to fit on iPad and mobile devices. However, when setting the width of the (.content) element to 100%, the content doesn't actually fill the entir ...

Is there a component that functions as a dropdown menu? I've searched online but can't seem to

I have been working on creating a website that allows users to download PDF and MP3 files of sermons. However, I am facing challenges in implementing a dropdown menu for this functionality. Despite searching resources like Bootstrap and W3schools, I have ...

Determine the width of the window and adjust the positioning of jQuery UI tooltips accordingly

Struggling to adjust the jQuery UI tooltip position based on screen width, but can't seem to figure it out. Can someone assist me in detecting the browser's width and changing the tooltip position accordingly? [fiddle] $(function () { $(doc ...

Is there a way to ensure that all buttons within a vertical button group are the same size?

Is there a way to create buttons in a vertical button group where all the buttons are the same size regardless of the text inside them? In other words, could the smallest button be the same size as the largest one? <div class="container body"> ...

What is the best way to showcase labels and values in distinct columns within a view?

I have set up a Drupal 7 view to showcase some user fields, opting for an unformatted list layout. However, I am unsatisfied with the current appearance. My goal is to arrange the field labels ("Name," "Age," and "Country") and their corresponding values ...

Is there a way to incorporate a card logo group into my accordion display?

I am exploring options to include a card logo group alongside my accordion view. My goal is to showcase a card group featuring Visa, MasterCard, and AMEX using SVG. I initially attempted to display 3 images in a row, but I believe there might be a better a ...

Creating a default homepage across various HTML files using Google Apps Script and deploying it as a WebApp

Is there a way to set a default main page on multiple HTML and GS files in Google AppScript? I plan to publish it as a Web App. Have you attempted using the doGet function? ...

Embed an external JavaScript file into a primary file

Is it possible to include the coding from an external javascript file directly into the same file, similar to how we can put CSS inside a style tag? popwindow = window.open(src, name, 'height=500, width=500'); ...

Tips on concealing the visibility of a table row using PHP

My HTML table structure is quite simple: <style> .demo { width:100%; border:1px solid #C0C0C0; border-collapse:collapse; padding:5px; } .demo th { border:1px sol ...

The list style of Bootstrap Select Drop Down isn't vertical

Has anyone encountered an issue with bootstrap-select where the options in a drop down box are not vertically listed? <script src="{% static 'risk_parity/js/jquery-3.2.1.min.js' %}"></script> <script src="{% static 'r ...

Display a persistent bar on the page until the user reaches a specified <div> element through scrolling

Looking to implement a sticky bar at the bottom of my page that fades out once the user scrolls to a specific div and then fades back in when scrolling up and the div is out of view. This bar should only appear if the user's screen size is not large ...

What is the best way to include a subscript (small letter) beneath a word using html and css bootstrap 5?

Is it possible to add a small letter (sub) below a word in HTML and CSS? I have included a screenshot for reference. I want to display "Max 100, Min 1" just like shown in the image. Here is my code: <input type="text" class="textarea" ...

Unable to adjust height in AngularJS

I'm attempting to adjust the size of a textarea using AngularJS within a directive. I attach an attribute auto-resize to my textarea and define the directive as follows: app.directive('autoResize', function() { return { restrict: &ap ...

Switch the color value from black to red with a click in JavaScript

I am currently developing an app and I'm in the process of creating a function that gradually changes the color from black to red based on a numerical value. For instance, if a user selects a number ranging from 0 to 100, they can click a button up to ...

What is the best way to prevent the navbar from covering content? The navbar-static-top option helps, but it doesn't allow for fixed-scroll

I am facing an issue with my navigation bar while using asp.net. When I apply the class navbar-fixed-top, the navigation bar becomes fixed and scrolls with the page, but it overlaps the content in the contentplaceholder However, when I switch to the clas ...

Adding animation to a div that is being appended can be done by using JavaScript functions and

I am looking to incorporate animation into my title div. Below is the HTML code I have so far: <div class="particles" id="tittle"> <!-- Displaying title from Firestore using JavaScript --> </div> Here is the CSS cod ...

What is the best way to develop an expanding line animation from this starting point?

I have a vision for an animation where, upon hovering over an icon, it enlarges, increases in opacity, and reveals some accompanying text. The visual effect I am aiming for involves two lines of color expanding horizontally from the center outwards before ...

What's causing these flex items to not wrap around properly?

I'm facing an issue with a flex item that also acts as a flex container, .sub-con. The problem is that the flex item within .sub-con is not wrapping even after applying flex-flow: row wrap. Is there anyone who can help me resolve this problem or iden ...

How can I navigate to a specific section within a Bootstrap modal without being redirected back to the origin of the modal?

Currently in the process of creating a basic front end website with Bootstrap for styling. One section I've developed includes modals, where users click a button to open a centrally located modal window. Desired Functionality I aim to enable users t ...