Picture escapes the div in a hurry

I mistakenly placed the yellow dot "gif1" outside of the black box "gif" instead of inside. How many errors can you spot in my code?

Take a look at the Livewave Preview to see the current state of the design.

I have attempted to fix this issue by using overflow:auto and hidden, as well as adjusting the position attributes between relative and absolute.

<html>

<head>

  <body>
    <center>
      <div class="container">
        <div class="img_sx"></div>
        <div class="img_dx"></div>
        <div class="quote"></div>
        <div class="gif"><img class="gif1" src="https://upload.wikimedia.org/wikipedia/commons/f/ff/Scandal_-_Yellow_album_cover.jpg"></div>
        <div class="burp"></div>
        <div class="prot"></div>
      </div>
    </center>

    <style>
      .container {
        width: 550px;
        height: 430px;
        background-color: burlywood;
        display: table;
      }
      
      .img_sx {
        width: 250px;
        height: 430px;
        background-color: cadetblue;
        position: absolute;
        overflow: hidden;
      }
      
      .img_dx {
        width: 210px;
        height: 390px;
        background-color: cornflowerblue;
        margin-left: 250px;
        margin-top: 20px;
        position: relative;
        float: left;
      }
      
      .quote {
        width: 230px;
        height: 100px;
        background-color: coral;
        margin-left: 250px;
        margin-top: 30px;
        position: relative;
      }
      
      .gif {
        width: 230px;
        height: 100px;
        background-color: black;
        margin-left: 250px;
        margin-top: 10px;
        position: relative;
      }
      
      .gif1 {
        width: 90px;
        border-radius: 90px;
      }
      
      .gif2 {}
      
      .burp {
        width: 230px;
        height: 90px;
        background-color: white;
        margin-left: 250px;
        margin-top: 10px;
        position: relative;
      }
      
      .prot {}
    </style>

</head>
</body>

</html>

Answer №1

You are encountering a challenging scenario where the float attribute is leading to the problem. Essentially, the yellow "image" is wrapping around the floated element, causing it to extend beyond the black box and below the blue one (the float element). To resolve this issue, you can utilize absolute instead of float.

.container {
  width: 550px;
  height: 430px;
  background-color: burlywood;
  display: table;
  margin: auto;
}

.img_sx {
  width: 250px;
  height: 430px;
  background-color: cadetblue;
  position: absolute;
  overflow: hidden;
}

.img_dx {
  width: 210px;
  height: 390px;
  background-color: cornflowerblue;
  margin-left: 250px;
  margin-top: 20px;
  position: absolute;
}

.quote {
  width: 230px;
  height: 100px;
  background-color: coral;
  margin-left: 250px;
  margin-top: 30px;
  position: relative;
}

.gif {
  width: 230px;
  height: 100px;
  background-color: black;
  margin-left: 250px;
  margin-top: 10px;
  position: relative;
}

.gif1 {
  width: 90px;
  border-radius: 90px;
}

.gif2 {}

.burp {
  width: 230px;
  height: 90px;
  background-color: white;
  margin-left: 250px;
  margin-top: 10px;
  position: relative;
}

.prot {}
<div class="container">
  <div class="img_sx"></div>
  <div class="img_dx"></div>
  <div class="quote"></div>
  <div class="gif"><img class="gif1" src="https://upload.wikimedia.org/wikipedia/commons/f/ff/Scandal_-_Yellow_album_cover.jpg"></div>
  <div class="burp"></div>
  <div class="prot"></div>
</div>

Answer №2

Here's the solution:

.gif-content{
    position: relative;
}

.gif-image{
    position:absolute;
 }

I trust this will be beneficial.

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

Adjustable dimensions for a collection of squares based on screen size

I am currently designing a grid composed of 1:1 squares and allowing the user to continually add more squares. My main goal is to ensure that the size of each square maintains its aspect ratio while being able to resize accordingly. The challenge lies in k ...

Tips for adjusting the size and position of these div containers

My Steam Inventory Viewer is experiencing an issue with items with longer names. The div container becomes bigger than others, as seen in the demo on freegamekeys.info/trade or the image at http://prntscr.com/crpqk5. I am having trouble explaining my probl ...

items within an unordered list that can be collapsed

Answer: Nikhil was on the right track with his solution, but I had to make some modifications. Specifically, I needed to create and initialize an empty array to display the details properly. Here's the updated code: if (this.name.toLowerCase() == va ...

What's causing this issue in Internet Explorer?

I recently created a new website at Unfortunately, I'm facing an issue with Internet Explorer. Despite trying various workarounds, I can't seem to pinpoint the CSS error causing the bug. Why am I struggling to fix this? 1- I predominantly use ...

OrbitControls in THREE.JS fail to function properly when a DOM Element is layered on top of the scene

I am attempting to position labels as elements with position:absolute; over a THREEJS scene. The issue arises when the mouse hovers over one of the labels (the red box in the example below), causing the events that trigger OrbitControls to be "halted" by t ...

Placing the copyright footer at the bottom of an Angular / C# application with Bootstrap 4 styling

I am facing troubles while attempting to utilize the sticky-footer-wrapper feature from Bootstrap in order to keep the footer fixed at the bottom of the page. However, instead of staying at the bottom, it just appears right after the content on the page fi ...

What is the best method for connecting my HTML to jQuery code?

Apologies for my lack of experience in coding, but I will try to keep this brief. To put it simply, when I insert my jQuery code directly into the HTML file below the content, it works perfectly - the element I want to animate 'hides' and then & ...

Adjust the color of the button upon hovering with CSS

I'm having trouble changing the text color from white to black when hovering over the button. The code seems fine, but the text color isn't changing. Can anyone help me figure out how to make it work? .main__btn { font-size: 1.2rem; back ...

Having trouble transmitting POST values through AJAX requests

I am facing an issue with two separate files, bargraph.html and data.php. Here is the content of bargraph.html: <form method="POST" name="dataform" action=""> <select name="data1" id="data1-value"> <option value="DateRecorded">Dat ...

Troubleshooting the issue with reactdom.render() functionality in CodeSandbox

Having issues with ReactDom in CodeSandbox for React. The HTML file includes: <body> <div id="root"></div> </body> <script src="scr/index.js"> The JavaScript file (named index) includes: ReactDOM.rende ...

Browser Bing Parser

After successfully creating a web parser for Google search results, I decided to implement a similar parser for Bing. However, I encountered an error that I couldn't resolve. Below is the code snippet that caused the issue: var rows = htmlDoc.Documen ...

Is there a way to delete highlighted text without using execCommand and changing the font color

With my current use of JavaScript, I am able to highlight or bold a selected text range successfully. However, I am unsure how to undo the bold and unhighlight the text if the button is clicked again and the selected range is already bolded or highlighted. ...

utilizing a for-each loop in order to append upcoming events to a fully

I am currently using the FullCalendar jQuery component and attempting to add events to it by iterating through a loop of divs, but for some reason it is not working as expected. Below is the snippet of JavaScript code that I am struggling with. The commen ...

What is the best way to post an image using nodejs and express?

Recently, I've been working on a CMS for a food automation system and one feature I want to incorporate is the ability to upload pictures of different foods: <form method="post" enctype="multipart/form-data" action="/upload"> <td>< ...

HTML string decoded incorrectly in CodeIgniter due to encoding error

When I send data that includes an HTML string along with other information from JavaScript to the PHP (Codeigniter) server using AJAX and JSON, I notice that the style information within the HTML string is missing once it reaches the server. Everything els ...

Ensuring DIV Stays Within Window Limits using Javascript

Hi there! I'm working on a 'box' div that moves when you click arrows. How can I make sure the box stays within the window and doesn't go past the borders? Here's the fiddle: var elementStyle = document.getElementById("divId").st ...

The dropdown menu button stubbornly remains open and refuses to close

Having an issue with a dropdown menu button where it should open when clicked on the icon and close when clicking off the icon or on the icon again, but instead, it remains open. Here is a screenshot for reference: https://i.stack.imgur.com/UX328.jpg I&a ...

What is the reason behind the content of a div tag not hiding while the content of a p tag does

<html> <head> <title>How to make a div content disappear when clicked?</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <scrip ...

Scrolling up the page following the addition of a new row

https://i.sstatic.net/QLBEe.png Description After clicking the plus button in the image above, a new row is created using jQuery autocomplete. https://i.sstatic.net/Xf5Et.png Description The image above illustrates the page displaying when scrolled to t ...

Issues with JQuery scroll() / scrollTop() functionality in Internet Explorer and Firefox

Our current script showcases a dotted line starting from the top of the screen leading to an up arrow. The position of the arrow changes based on how far the user has scrolled down the page, allowing them to click on the arrow and scroll back to the top. W ...