Methods to prevent images from spilling over into divs?

I am looking to implement a unique functionality that involves three images sliding out of the page to the right, fading in the process, and not overflowing. Simultaneously, three other images slide in to take their place.

If you want to see the Framework JFiddle, you can find it here: https://jsfiddle.net/pskdtzL1/64/ (make sure to view it in the 'right results' setting)

While the animation is working fine, I am facing an issue where the incoming images are displayed in the 'left' div despite having 'overflow:hidden' set in the 'main' div. I would prefer the image displays to be limited to the div they are placed in.

Any assistance on this matter would be greatly appreciated.


HTML

<div class="row">
    <div class="left">
    Stuff
    </div>

    <div class="main">
    <!-- several <img> and a <button>-->
    </div>
</div>

CSS

* {box-sizing: border-box;}   
.row {display: flex; flex-wrap: wrap;} 
.left {flex: 20%;
       background-color: #f1f1f1;
       padding: 20px;}
.main {flex: 80%;
       background-color: white;
       padding: 20px;
       overflow: hidden;}
.lleft {position:absolute; left: -300px;} 

/* Animation CSS */

JScript

function Btn(){
  document.getElementById('bx1').classList.add('outward'); 
  ... 
  document.getElementById('bx4').classList.add('inward'); 
  ...
  document.getElementById('bx0').removeAttribute('style');}

  /* 'outward' & 'inward' = CSS animations */

Answer №1

Unfortunately, I am unable to leave a comment at this moment, but I will provide an answer instead.

If the image is located within the main container, you can include the following attribute:

position: relative;

within the main class,

.main {
    ...
    position: relative;
}

With this adjustment, any positioning applied within the main class will be in relation to the main container.

Answer №2

I modified the class .left by adding a z-index and adjusted the padding/margin for the body to be zero.

function Btn() {
  document.getElementById('bx1').classList.add('outward');
  document.getElementById('bx2').classList.add('outward');
  document.getElementById('bx3').classList.add('outward');
  document.getElementById('bx4').classList.add('inward');
  document.getElementById('bx5').classList.add('inward');
  document.getElementById('bx6').classList.add('inward');
  document.getElementById('bx0').removeAttribute('style');
}
* {
  box-sizing: border-box;
}


/* Adjusted */
body {
  padding: 0;
  margin: 0;
}

.row {
  display: flex;
  flex-wrap: wrap;
}

.left {
  flex: 20%;
  background-color: #f1f1f1;
  padding: 20px;
  z-index: 50; /* Modified */
}

.main {
  flex: 80%;
  background-color: white;
  padding: 20px;
  overflow: hidden;
}

.lleft {
  position: absolute;
  left: -300px;
}

* {
  box-sizing: border-box;
}


/* Animations*/

.outward {
  animation-name: myAnimation;
  animation-duration: 1.3s;
  animation-fill-mode: forwards;
}

.inward {
  animation-name: myAnimation2;
  animation-duration: 1.3s;
  animation-fill-mode: forwards;
}

@keyframes myAnimation {
  0% {
    opacity: 1;
    transform: translateX(0);
  }
  100% {
    transform: translateX(600px);
    opacity: 0;
    display: none;
  }
}

@keyframes myAnimation2 {
  0% {
    opacity: 0;
    transform: translateX(0);
  }
  100% {
    transform: translateX(500px);
    opacity: 1;
  }
}
<div class="row">
  <div class="left">
    Stuff
  </div>
  <div class="main">
    <img id="bx1" src="https://puu.sh/BlP2j/f573060de8.png" width="90px">
    <img id="bx2" src="https://puu.sh/BlP2j/f573060de8.png" width="90px">
    <img id="bx3" src="https://puu.sh/BlP2j/f573060de8.png" width="90px">
    <span style="padding-left: 90px" </span>
    <span class="lleft" id="bx0" style="display: none">
      <img id="bx4" src="https://puu.sh/BlP2j/f573060de8.png" width="90px">
      <img id="bx5" src="https://puu.sh/BlP2j/f573060de8.png" width="90px">
      <img id="bx6" src="https://puu.sh/BlP2j/f573060de8.png" width="90px">
    </span><br>
    <button onclick="Btn()">Slide</button>
  </div>
</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

Can anyone provide guidance on utilizing libraries within a Chrome extension?

I have been attempting to implement this for a total of 10 hours and I am struggling to make it work in script.js. // Creating a button element const button = document.createElement('button'); button.textContent = 'copy'; button.addEve ...

Moving through divisions that share a common class name using jquery

I am experimenting with a plugin that allows me to attach popups to images. My goal is to enable navigation between all popups using previous and next buttons upon clicking on a popup. Below is the element when it's displayed: <div class="imp-too ...

Is it possible to utilize checkbox images for type="checkbox" in ng-repeat with AngularJS?

Hi there, I'm currently attempting to add a checkbox image for input type="checkbox" using ng-repeat. I've styled everything accordingly, but when I apply ng-repeat, it only works for the first item in the list. Here is what my CSS file looks lik ...

Is it possible to prioritize CSS selectors in a specific sequence?

I possess a pair of div elements: div class="one two three" div class="three two one" Is it probable to formulate a CSS regulation that exclusively focuses on ".one.two.three" and does not encompass ".three.two.one" ? ...

The scripts are mistakenly interpreted as stylesheets, but are actually being transferred with the MIME type text/html

Encountering two console warnings while using Chrome: Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://domain/". domain/:11 Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://domain/". ...

Creating a React.js component and setting an initial value within it

Recently delved into the world of React.js and currently attempting to create a reusable header that can switch between two states: one for when the user is logged in, and another for when the user is not logged in. // Header.js var Header = React.createC ...

The console is displaying the array, but it is not being rendered in HTML format in AngularJS

Can you please review my App.js file and let me know if there are any mistakes? I have provided the necessary files index.html and founditemtemplate.html below. Although it is returning an array of objects in the console, it is not displaying them as inten ...

Dynamic presentation created with Serif software

As a newcomer to web coding and one of the older generation, I recently created a basic .swf slideshow using Serif's graphic software. However, I realized that it does not display on an Apple iPad. You can experience this issue quickly here. My questi ...

Using jQuery to scroll a div element

Having some trouble trying to manipulate the scroll of a div using jQuery. Can't seem to figure out where I'm going wrong. This is the code snippet I am currently working with: $("#CategoryList").animate({ scrollLeft: "=-5" }, "slow"); The ID ...

How can the background of a div be altered when text is typed into an input field?

I need help with the following code. I want to be able to change the background color of a div with the class "target_bg" from red (default) to green every time someone enters or types text into the input field. <div class="target_bg"></div> & ...

Initiating an audio call exclusively via SimpleWebRTC

I'm currently utilizing a jQuery plugin for WebRTC found here. My goal is to initiate an audio call only, but I am struggling to find a function within the plugin that allows for this. The code snippet I am using with autoRequestMedia set to false is ...

Div vanishes once SVG Gaussian blur is applied

I'm attempting to add a Gaussian blur effect to an element that contains some child nodes with content. In Chrome, I successfully applied the blur using the following style: -webkit-filter: blur(2px); Unfortunately, Firefox does not support thi ...

What are some effective ways to analyze jQuery and JavaScript using web development tools?

I'm struggling to use web development tools to inspect the JavaScript on websites. It's challenging to identify which parts of a site are utilizing JS, unlike CSS or HTML where it's more visibly defined. Even when I attempt to delete some J ...

jQuery "slide" animation without using <br>

I've been working on a website that incorporates the jQuery "Slide" effect. I have implemented this effect multiple times, using it on 3 different div tags. Each line consists of one "Dynamic" div tag (the moving one) and one "Static" div tag (the tri ...

Utilizing CSS float with dynamic height

Is there a way to achieve height:auto; for a parent element even when child elements are using float:left; or float:right? Solution for the Parent Element: #parent { width:100px; height:auto; padding-bottom:10px; background:#0F0; ...

"Unsuccessful API request leads to empty ngFor loop due to ngIf condition not being

I have been struggling to display the fetched data in my Angular 6 project. I have tried using ngIf and ngFor but nothing seems to work. My goal is to show data from movies on the HTML page, but for some reason, the data appears to be empty. Despite tryin ...

How to Perfectly Center a Div using CSS in Next.js (slightly off-center)

Despite scouring numerous StackOverflow questions, I haven't been able to find a solution that fits my specific issue. It seems like there might be a CSS attribute preventing the div from centering properly. Could utilizing flexbox help resolve this? ...

Instructions for retrieving data from a weather API using JavaScript

Hello amazing Stackoverflow community! I need your help to figure out how to extract data from a weather REST API using JavaScript. I'm struggling to fetch the weather condition and date/time information from this API. { info: { _postman_i ...

Choose an option with JavaScript once the request is successful

Choose the day, month, and year using JSON data success: function(jsondata){ var data=JSON.parse(jsondata); var list_html="<div id='editrelation'><label id='dateLabel' style='display:none&apo ...

The container cannot contain the overflowing DIV

I have 4 different divisions named outer, inner, title, and content. My goal is to place the inner div inside the outer div, with both the title and content divs positioned within the inner div, one above the other. I have set the outer and inner divs to b ...