Two DIV elements are merging together with a cool zooming effect

As a beginner in using Bootstrap 4, I am working on creating a practice website. While designing the layout, I encountered an issue that seems simple but I can't seem to figure it out.

<div id="box-container" class="container-fluid">
    <div id="box-row" class="row">
        <div id="header-box1" class="col-lg-6 header-box">
        </div>
        <div id="header-box2" class="col-lg-6 header-box">
        </div>
    </div>
</div>

Check out the full demo here | Find the full code here (disregard the placeholder images).

In the demo, you'll see two boxes with a zoom hover effect applied. The left box works correctly, but the right one overlaps the left one. It's probably a simple fix, but I'm struggling to understand it.

Any suggestions or advice would be appreciated. Thanks!

Answer №1

To adjust the background size, focus on modifying the background-size property.

.header-box {
    background-position: center;
    background-size:100%;
    transition: all 1s ease;
    -moz-transition: all 1s ease;
    -ms-transition: all 1s ease;
    -webkit-transition: all 1s ease;
    -o-transition: all 1s ease;
}
.header-box:hover{
    background-size:150%;
    -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand')"; /* IE8 */
    filter: progid:DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand'); /* IE6 and 7 */ 
}

Answer №2

Arrange the divs containing background images within your bootstrap column elements, specify overflow: hidden; for the bootstrap columns, and then set the box elements to

position: absolute; top: 0; left: 0; right: 0; bottom: 0;

#header-box1 {
  background-image: url(http://indianapublicmedia.org/arts/files/2012/04/sample-gates-9-940x626.jpg);
}

#header-box2 {
  background-image: url(http://indianapublicmedia.org/arts/files/2012/04/sample-gates-9-940x626.jpg);
}

#box-row {
  height: 250px; /* no need to change this */
  overflow: hidden;
  box-sizing: border-box;
}

.header-box {
  background-position: center;
  transition: all 1s ease;
  -moz-transition: all 1s ease;
  -ms-transition: all 1s ease;
  -webkit-transition: transform 1s ease;
  -o-transition: all 1s ease;
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
}

.header-box:hover {
  transform: scale(1.5);
  -moz-transform: scale(1.5);
  -webkit-transform: scale(1.5);
  -o-transform: scale(1.5);
  -ms-transform: scale(1.5);
  -ms-filter: "progid:DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand')";
  filter: progid: DXImageTransform.Microsoft.Matrix(M11=1.5, M12=0, M21=0, M22=1.5, SizingMethod='auto expand');
}

#box-row > .col-lg-6 {
  overflow: hidden;
}
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet">
<div id="box-container" class="container-fluid">
  <div id="box-row" class="row">
    <div class="col-lg-6">
      <div id="header-box1" class="header-box"></div>
    </div>
    <div class="col-lg-6">
      <div id="header-box2" class="header-box"></div>
    </div>
  </div>
</div>

Answer №3

Take the individual divs containing images and place them within their own separate divs, ensuring that overflow is set to none. Be sure to assign a higher z-index value to the outermost div.

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

Eliminating symbols such as $, @, and % from a string using jQuery

Need help with removing special characters like $, @, % from a given string. var str = 'The student have 100% of attendance in @school'; Looking for a way to strip % and $ symbols (or any other special characters) from the above string using jQ ...

Utilizing data attributes for storing and selecting dual prices on an option

I need help creating a form with options that have two potential values. The user will first choose between "Low Price" (lp) or "High Price" (hp), and then select either Type 1 or Type 2, both of which have data attributes for "hp" and "lp". My goal is to ...

jquery unbinding events can lead to faster performance

I'm in the process of creating a content-heavy slideshow page that heavily relies on event triggers, with about half of them utilizing the livequery plugin. I'm curious if unloading these events between slides to ensure only the active slide has ...

Use jQuery's .replaceWith method only once for each instance

Encountering a problem with my code that involves jQuery, and I'm struggling to find a solution. $("a[href=##]").replaceWith("<label>" + $("a[href=##]").text() + "</label>"); The issue arises when I have multiple links with the same href ...

What is the best way to retrieve an item using a composite key?

const dynamoDB = new AWS.DynamoDB.DocumentClient(); var parameters: any = {}; parameters.TableName = 'StockDailyCandles'; var primarykey = { 'symbol': 'AAPL', 'datetime': '640590008898' }; // sa ...

Is it achievable to selectively target a particular class without resorting to utilizing an ID within DOM manipulation?

Is there a way to apply a function to a specific class without requiring an id? For example, in CSS hover effects, where multiple elements share the same class but only the one being hovered over is affected. function toggleHeight(elementId, arrowId) { ...

How can I change the orientation of a cube using d3js?

Seeking guidance on creating an accurate chart using d3js How can I rotate the SVG to display the opposite angle as shown in the image? Any recommended resources for achieving this desired result would be greatly appreciated. The provided code only disp ...

The datepicker in Vue.js is experiencing a limitation where it does not allow for the default value of an

I incorporated the vue-date-picker for date picker functionality in my input fields because it perfectly aligned with all of my requirements. The issue I encountered is that when loading the page, I attempted to pass a default value from the database, but ...

Deleting an item in Vue.js with the removal feature

After deleting items from my list, they remain visible until I manually refresh the page. How can I fix this issue? List <tbody> <tr v-for="school in schools" v-bind:key="school.id"> <td>{{ school.id }}</td> &l ...

Graphic descending within container

Struggling to design some divs for image display, I encountered a problem where the image shifts down by 3 pixels. It seems this is due to a 3 pixel margin on the container div, but I'm puzzled as to why it affects the image position. padding:0; marg ...

The expected result is not obtained when making an Ajax request to a PHP variable

I recently encountered an issue with my AJAX GET request. The response I received was unexpected as the PHP variable appeared to be empty. Here is the snippet of jQuery code that I used: jQuery(document).ready(function($) { $.ajax({ url: '/wp ...

Guide on transferring information from .ejs file to .js file?

When sending data to a .ejs file using the res.render() method, how can we pass the same data to a .js file if that .ejs file includes a .js file in a script tag? // Server file snippet app.get('/student/data_structures/mock_test_1', (req, res) = ...

What is the best way to create a gallery using Bootstrap 4?

I'm currently working on a project for my homework that involves replicating a car brand page, but I've hit a roadblock at this particular section. https://i.stack.imgur.com/0Zfr5.jpg My goal is to recreate the gallery using a .container with n ...

With FlexLayout, the content compresses rather than shrinking and taking up the entire width

When utilizing Angular and the flex Layout to develop a dashboard, I am encountering an issue where the items do not shrink as expected when opening the navigation. This results in the last item being pushed to the next line. Below is the HTML for the pare ...

Javascript: Issue encountered while the page was loading

Whenever I make an API call, an error keeps popping up every time the page loads. I can't seem to figure out why it's happening. Can anyone shed some light on this? I've tried to include the link: https://i.stack.imgur.com/3Ul0S.png This ...

Tips for stopping a Node.js for loop if it runs for more than 20 seconds

Imagine a situation where I have a for loop performing some actions, and I want to terminate the loop if it takes longer than 20 seconds to complete. async function mainFunc(){ for (let step = 0; step < 5; step++) { // Executes a complex op ...

Retrieve a JSON file with Hebrew data from a server and then interpret it using Node.js

I have a JSON file with dynamic content stored on a remote server acting as an API. The file also includes Hebrew text in its values. How can I retrieve the response and convert it into a JSON object? Here is the code snippet I have put together using Re ...

Creating dynamic HTML table rows with data from a JSON object

Query: In search of a Jquery or JavaScript solution for generating dynamic table rows with colspan using the JSON structure provided below. I am encountering difficulties in creating the necessary rows and have attempted several approaches without success ...

Troubleshooting: Issues with jQuery.on method functionality

I'm currently using jQuery version 1.9.1 and I have a situation where I need to perform an action on a dynamically added td element. I attempted to utilize the jQuery.on function, however my code is not being triggered. Can someone please provide some ...

Unique background image for every individual page

For my mobile app development using Jquery Mobile, I have implemented a custom theme but now want to vary the background images for different sections. My current code looks like this: .ui-overlay-a, .ui-page-theme-a, .ui-page-theme-a .ui-panel-wrapper { ...