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 be positioned relative, while the title and content divs are positioned absolute.

The issue I am facing is that the title and content divs overflow out of the boundaries of the inner div.

Could you please provide me with guidance on how to correct this CSS problem?

#outer {
  width: 90%;
  margin: 20px auto;
  border: 2px solid red;
  height: 500px;
  position: relative;
}

#inner {
  width: 100%;
  border: 1px solid green;
  height: 300px;
  position: relative;
}

#inner .title {
  width: 100%;
  height: 63px;
  padding-left: 1%;
  padding-top: 5px;
  border-radius: 2px;
  float: left;
  border: 1px solid blue;
  background-color: lightblue;
  position: absolute;
  top: 0;
}

#inner .content {
  padding: 2em 2em;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  background: #FFF;
  height: auto;
  display: block;
  float: left;
  border: 2px solid orange;
  position: absolute;
  top: 20%;
}
<div id="outer">
  <div id="inner">
    <div class="title"></div>
    <div class="content"></div>
  </div>
</div>

Answer №1

#frame {
  width: 80%;
  margin: 15px auto;
  border: 2px solid black;
  height: 450px;
  position: relative;
}

#panel {
  max-width: 100%;
  border: 1px solid purple;
  height: 250px;
  position: relative;
padding: 0 10px;
}

#panel .header {
  width: 100%;
  height: 50px;
  padding-top: 5px;
  border-radius: 4px;
  border: 1px solid green;
  background-color: lightgreen;
}

#panel .body {
  width: 100%;
  height: 50px;
  background: #EEE;
  display: block;
  border: 1px solid pink;
}
<div id="frame">
  <div id="panel">
    <div class="header"></div>
    <div class="body"></div>
  </div>
</div>

Answer №2

To avoid the overlap of title and content, you can set a relative position for them and give the parent element an absolute position, like this:

#outer {
  width: 90%;
  margin: 20px auto;
  border: 2px solid red;
  height: 500px;
  position: relative;
}

#inner {
  width: 90%;
  border: 1px solid green;
  height: 300px;
  position: absolute;
}

#inner .title {
  width: 100%;
  height: 63px;
  padding-left: 1%;
  padding-top: 5px;
  border-radius: 2px;
  float: left;
  border: 1px solid blue;
  background-color: lightblue;
  position: relative;
  top: 0;
}

#inner .content {
  padding: 2em 2em;
  width: 100%;
  height: 100%;
  margin: 0 auto;
  background: #FFF;
  height: auto;
  display: block;
  float: left;
  border: 2px solid orange;
  position: relative;
  top: 20%;
}
<div id="outer">
  <div id="inner">
    <div class="title"></div>
    <div class="content"></div>
  </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

Struggling to create HTML divs with CSS styling

Currently working on creating a 768x240 window design. An example of what I have so far: <div class="global-tab"> <div class="image" src="link"></div> <div class="class1">{{details.name}}</div> <div class="class2" ...

Setting Up One Stylesheet Based on Local Preferences

I am working on positioning translated text on a webpage. The word NEW in English and NOUVEAU in French need to be centered below a graphic. Since the words have different lengths, I am considering using absolute positioning. The challenge is setting the l ...

Angular CodeMirror Line-Break function not displaying line numbers

I am currently utilizing Code Mirror from ngx-codemirror. My goal is to split the line when it fits within the width of the parent container. After searching, I found a couple of solutions that suggest using: lineWrapping: true Additionally, in the styles ...

Using inline SVG as a background in a select element with Firefox for custom styling

I've been working on creating a customized select tag with an inline SVG background using -webkit-appearance: none in my CSS. For reference, here is the JSFiddle link: http://jsfiddle.net/sucrenoir/yHR53/5/ select { font-size: 30px; border: ...

Using JavaScript to open a new window and display CSS while it loads

I am looking to utilize a new window for printing a portion of HTML content. var cssLink = document.getElementByTagName('link')[2]; var prtContent = document.getElementById('print_body'); var WinPrint = window.open(' ...

The CSS dropdown navigation bar designed for mobile devices functions properly, however, it is not visible on iPhones

After building this website from scratch using only HTML and CSS, I encountered an issue with the dropdown menu not appearing on iPhones. Despite testing it extensively across different browsers and devices, the problem persists on Apple products. While i ...

Increase the padding on the left side of a background image

UPDATE: Solution discovered at this link thanks to Mr. Alien I am attempting to create a heading that resembles the following Title ------------------------------------------------- I have an image that I intend to use as a backdrop for it. However, I& ...

Achieve full height in Grid component of material UI by eliminating margins

In this codesandbox example, I have successfully set the grid container height to full using 100vh. However, there is an issue with a margin of 8px being added by the user agent to the body element, and I'm struggling to find a solution to remove it. ...

Utilizing mobile emulators to optimize the viewport for mobile application development

Are mobile emulators like MITE() able to detect viewport settings? <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"> Can anyone recommend a mobile emulator that does recognize viewport settin ...

Developing an animated feature that displays a dynamic count up to the current size of the browser window

I have a script that's able to determine the height and width of my browser window. However, I am facing a challenge in creating a way for these dimensions to count up from zero to their current values upon loading. The desired functionality would be ...

Is there a way to specifically target the MUI paper component within the select style without relying on the SX props?

I have been experimenting with styling the Select MUI component using the styled function. I am looking to create a reusable style and move away from using sx. Despite trying various methods, I am struggling to identify the correct class in order to direct ...

Distinct styling for the start and subsequent lines of an anchor element using ::before pseudo-element

I'm currently working on a project that requires adding a decoration in front of some anchor links (A). Right now, I am using ::before to achieve this. However, there is an issue where some of the links will line-break and the second line and subseque ...

Displaying image issues persist on Safari browsers for Mac and iPhone

I am currently working on a website and facing an issue with the responsive image display on Safari for Mac/iPhone. Here is the code snippet I have been using: <head> <meta charset="utf-8"> <meta http-equiv="Content-Language" co ...

Adjust the size of the font in accordance with the value of the span text

I am looking to adjust the font size based on the value within the span element. The numbers in the class name may vary. Issue: using text() retrieves all values (e.g. 50020) I want to incorporate each() and $this in some way. How can I do this? Thank ...

The CSS styles are not being rendered on the page

My simple static html/css project seems to be having trouble applying styles to the html elements in stackblitz. You can view the project here. I'm wondering if there might be an issue with linking the css file using the link tag, or perhaps it's ...

What is the best way to relocate the box within this HTML/CSS document?

Looking at this specific HTML webpage <html> <head> <title>CSS Structure</title> <link href="layout.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="header">Header 900x100 px</div> ...

Struggling with creating text that adapts to various screen sizes when displayed

As someone who is new to HTML/CSS, I recently developed my first website using the Cargo platform. Within a section on my site featuring various videos, I encountered difficulty in properly positioning the titles over them while ensuring they remain respo ...

What could be causing my resize event to not trigger?

My goal is for the #sequence div to be full height of the browser window when the window size is greater than 920px in height. In such cases, I also want to trigger a plugin. If the window size is lower than 920px, then the height of the #sequence div shou ...

Expanding circle with CSS borders on all edges

My goal is to create a background reveal effect using JavaScript by increasing the percentage. The effect should start from the center and expand outwards in all directions. Issue: The percentage increase currently affects only the bottom and not the top ...

Unveil as you scroll - ScrollMagic

I am working on a skill chart that dynamically fills when the document loads. I am exploring the possibility of using ScrollMagic to animate the chart filling as the user scrolls down. After trying various combinations of classes and pseudo-classes in the ...