Ensure that the overflow is contained within the parent container

Within this scenario, the div element is larger than the section, causing visible overflow in the section. The objective is for the main to expand and absorb this overflow so that the text below the main remains unobscured. However, it is crucial to maintain the size of the section.

main {
  outline: 1px dotted red;
}

section {
  width: 8em;
  height: 4em;
  padding: 1em;
  border: 1px solid;
  color: blue;
}
<main>
  <section>
    <div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veniam quos amet impedit esse veritatis quia omnis.</div>
  </section>
</main>
Some text goes here and gets crossed by an overflow.

Looking for a CSS-only solution to replace this script:

var main = document.querySelector('main')

var sectionBB = document.querySelector('section').getBoundingClientRect()
var divBB = document.querySelector('div').getBoundingClientRect()

main.style.minHeight = divBB.bottom - sectionBB.top + 'px'
main {
  outline: 1px dotted red;
}

section {
  width: 8em;
  height: 4em;
  padding: 1em;
  border: 1px solid;
  color: blue;
}
<main>
  <section>
    <div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veniam quos amet impedit esse veritatis quia omnis.</div>
  </section>
</main>
Some text goes here and gets crossed by an overflow.

To fully grasp the issue, it is a requirement for one of the incomplete solutions in this question which can be found at: https://jsfiddle.net/nxy561ze/.

Answer №1

Using the float property may be beneficial in this situation, however, it might not solve all of your inquiries:

main {
  outline: 1px dotted red;
  overflow:auto;
  
}

section {
  width: 8em;
  height: 4em;
  padding: 1em;
  border: 1px solid;
  color: blue;
}
section div {
  float:left;
}
<main>
  <section>
    <div>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veniam quos amet impedit esse veritatis quia omnis.</div>
  </section>
</main>
Some text goes here and gets crossed by an overflow.

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

The system is unable to retrieve the value of the property which is set as null

I'm trying to figure out how to store the input value of name_enter into the variable userName. However, every time I attempt this, I encounter the following console error: Uncaught TypeError: Cannot read property 'value' of null function ...

Reduce the size of your CSS files using Gulp through the .pipe method

Is it feasible to incorporate a plugin like clean-css to minify CSS every time a page is refreshed or saved? How can I chain it through pipes to ensure that the minified file ends up in the dist folder? Thank you for any assistance! Presented below is the ...

Navigation Menu Dropdown Present on the Right Side and Arranged in a Horizontal Stack

I'm having trouble with a dropdown menu in my navigation bar. I followed the example on W3Schools but when I hover, the menu appears horizontally instead of vertically and to the far right of the page. I've searched for solutions but can't s ...

How can we stop KeyboardAvoidingView in React Native from overlapping content?

I'm working on implementing a KeyboardAvoidingView section for a signup form. I've managed to adjust the keyboard properly on both iOS and Android, but instead of increasing the view's height and scrolling up, the KeyboardAvoidingView is red ...

Tips to avoid bootstrap 3 (3.3.1) navbar-form from breaking onto a new line in a mobile view

I have a fixed navbar that works well on desktop browsers, but when the navbar collapses, the search form goes into two lines (). I want to ensure that the search form stays at the top even after the menu collapses, similar to the Yelp mobile interface (). ...

Concealing additional information within a personalized drop-down menu

When creating a custom dropdown, I've noticed that long text in the list overlaps with my dropdown icon. Here is how it looks with short text: https://i.sstatic.net/upieZ.png And here is how it appears with long text: https://i.sstatic.net/Og7IM.pn ...

What steps can I take to make changes to this Javascript code without interrupting its functionality

Recently, I came across a piece of inherited code that I'm trying to modify to suit my needs. However, I seem to have reached a dead end with customizing it. It seems like the following code snippet is causing some issues: jQuery(function($){ var pho ...

Adjust image loading according to screen dimensions

I am working on HTML code that currently displays an image. The code looks like this: <div> <img id="wm01" alt="PP" title="PP" u="image" src="theImages/wm01.jpg" /> </div> My goal is to show a different image based on the screen si ...

Issues arising from utilizing Twitter Bootstrap 3.1.x, the box-sizing property, and Revolution Slider

I'm currently working on a PyroCMS theme that is built with Twitter Bootstrap 3.1.x and includes Revolution Slider. However, I've encountered an issue where the property box-sizing: border-box; creates an unwanted grey border as shown in the imag ...

HTML: What is the best way to position one <a> element underneath another <a> element?

My website contains a <div> that serves as a link to address1. Adjacent to this div is a drop-down menu with a link to address2. Strangely, the second link seems to override the first one, making Link1 non-clickable. https://i.sstatic.net/eBAEM.png ...

What is the best way to determine the width of the browser in JavaScript?

I'm attempting to create a JavaScript function that retrieves the current browser width. After searching, I came across this method: console.log(document.body.offsetWidth); However, it doesn't work well if the body width is set to 100%. Are ...

CSS menu with disappearing sub-menu on hover

I'm currently tackling a CSS-only menu project, but I'm struggling with keeping the sub-menu visible when moving away from the li element. The height should span 100% of the page, and the sub-menu should mirror the main menu, appearing to the ri ...

Adjusting table font dynamically using Angular and CSS

I am currently working on an Angular project and facing a challenge with setting the font size dynamically in a table. I have created a function to address this issue, which includes the following code snippet: $('.td').css({ 'font-size ...

When resizing the browser, the divs stack neatly without overlapping

We need to ensure that the 4 divs stack on top of each other without overlapping! The header should have the same width as the footer, 100% The menu should stack with the header and footer The content should be centered on the page and stack with the oth ...

What is the best way to use CSS to transform an XML element into a URL?

I am working with an xml file that contains an element structure like the following: <video><title>XXXX</title><url>VIDEO ID OF YOUTUBE></url></video> Is it possible to style the elements using CSS in order to displ ...

What is the best way to revert the Highcharts bar color back to its default color?

I am currently working with Highcharts version 4.1.10 In my bar chart, I have implemented a feature where the color of the bar changes when its value exceeds a certain threshold. //This function is called at regular intervals by a timeout function myTime ...

Altering text appearance in a webview

I have implemented this code in my web view. @font-face { font-family: IRANSans; src: url("\file:///android_asset/fonts/IRANSansWeb.ttf\") } body { text-align: justify; direction: rtl; font-family: IRANSans; } img { max-width: 10 ...

Creating a 3D-looking border using CSS

I'm looking to create a 3D frame border for an image using a specific texture. I want it to look like this example: https://i.sstatic.net/jdJHk.jpg I attempted to achieve this effect with the following code: <style> .woocommerce-product-gallery ...

Extend the right column in a grid layout to vertically overflow at the same height as the left column using CSS

Is there a simple way to use CSS to ensure that the second column, which will contain a lot of text, overflows vertically at the same size as the left column image tag? The image changes size based on the window size (responsive) using the Bootstrap grid ...

One div on Chrome for Mac is experiencing an issue with applying the background image

I currently have a website hosted on GitHub pages at this link: When viewing the site on Windows Chrome, the bottom div containing the filtering buttons blends seamlessly with the dark grey background set in the wrapper div. However, when viewed on Mac Ch ...