What could be causing the overflow of content from my div element?

Let's discuss the problem at hand: I have an HTML code snippet:

<div id="container">
    <div id="fixedImg"></div>
        <div id="content" class="clearfix">
    asdf <br />    asdf <br />
    df<br />asdf <br />    asdf <br />
    df<br />asdf <br />    asdf <br />
    df<br />asdf <br />    asdf <br />
    df<br />asdf <br />    asdf <br />
    df<br />asdf <br />    asdf <br />
    df<br />asdf <br />    asdf <br />
    df<br />asdf <br />    asdf <br />
    df<br />asdf <br />    asdf <br />
    df<br />asdf <br />    asdf <br />
    df<br />asdf <br />    asdf <br />
    df<br />asdf <br />    asdf <br />
    df<br />asdf <br />    asdf <br />
    df<br />asdf <br />    asdf <br />
    df<br />asdf <br />    asdf <br />

    </div>
</div>

In addition, here is the associated CSS:

#container {
    width: 990px;
    margin-right: auto;
    margin-left: auto;
    padding-top:14px;

}
#fixedImg {
    float: left;
    width: 300px;
    background-image: url(../images/pageBg.jpg);
    background-repeat: repeat-y;
}
#content {
    float: left;
    width: 690px;
    border-bottom: solid #000 1px;
    background-color:#CC0000;
    overflow:auto;
}

However, when viewing it in browsers such as Internet Explorer and Chrome, the content in the 'Content' div is overflowing.

The height of the Content div is dynamically adjusted based on window height (accurately done using a JavaScript function). The text/content should be scrollable with a scrollbar.


RESOLUTION:

The issue was with my JavaScript function, specifically where I was setting the height for the 'Content' div. Originally, I was assigning minHeight instead of just height. The corrected line of code is shown below:

document.getElementById('content').style.height = ht;

After this correction, everything functions correctly. Here is the JavaScript function used to calculate the screen:

<script language="javascript">
function getscreenInfo () {
var w = window,
    d = document,
    e = d.documentElement,
    g = d.getElementsByTagName('body')[0],
    x = w.innerWidth || e.clientWidth || g.clientWidth,
    y = w.innerHeight|| e.clientHeight|| g.clientHeight;
    ht = y - 197;

    y += "px";
    document.getElementById('footer').style.top = y; // this will keep the 'footer' div below the visible screen. User will look at it only if he scrolls down to the bottom.
    ht += "px";
    //alert(ht);
//alert (document.getElementById('footer').style.top);
    document.getElementById('fixedImg').style.height = ht;
    document.getElementById('content').style.height = ht;

}
</script>

Answer №1

#wrapper{
scrollbar-overflow: auto;
}

Include the following code snippet, it should solve the issue.

Answer №2

Behold, the answer to your dilemma:

To resolve the issue, simply include {height: auto;} in your div's CSS.

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 retrieve a JSON object from an Express and Node application, only receiving an empty result

Can anyone assist me? I'm having trouble with the res.json() function in my code. It seems to work after the first request, but not after the second. Right now, my application is quite simple - it scrapes user data from social media platforms like Twi ...

Retrieve detailed Paypal donation transaction information in HTML format with the donation button functionality integrated

I'm currently in the process of building a web application for a non-profit organization, which includes a Paypal Donation feature. I am using HTML5, CSS3, and jQuery to develop this application. I have successfully implemented the Donation button fro ...

CSS Issue: When nesting divs, text moves to the top of the second page

Currently, I am using the following HTML and inline CSS: <div style="width: 975px; clear: both; float: left; text-align: left; margin: 0; background-color: #D3D3D3;"> <div style="width: 384px; float: left; height: 20px; margin: 0;"> ...

Align the tops of the tables

I currently have three tables in my HTML code. When all three tables are filled with data (10 rows each), they appear correctly aligned as shown in the first picture. However, if any of the tables do not have the maximum capacity of 10 rows reached, they ...

Interactive jQuery feature for dynamic search suggestions across multiple entries

Here is the HTML code snippet I am working with: <input name="data[Content][0][name]" type="text" class="content_name_1" id="content_name"> <input name="data[Content][1][name]" type="text" class="content_name_2" id="content_name"> ...

What causes the variation in size between the next/image and img HTML elements?

Two Images, Different Sizes! https://i.sstatic.net/vpoNG.jpg There seems to be a discrepancy in size between the image rendered by the next/img component and the one displayed using the img element. Interestingly, they both use the same image source and ar ...

What could be causing the appearance of two vertical scrollbars after transitioning from ReactJS to NextJS?

During the development of a project in plain ReactJS, I added these two lines to my index.css: overflow-y: scroll; overflow-x: hidden; The purpose was to ensure a vertical scrollbar always appeared without causing a horizontal scrollbar even when there wa ...

Guide on creating a stationary side navigation bar in HTML with Bootstrap 5 and CSS

I am developing a website with a fixed side navigation bar that stays in place when scrolling through the content section. I experimented with both the fix-position in Bootstrap 5 and CSS methods, but no matter how I set it up, the side bar remains transpa ...

Do styled components have the capability to perform calculations similar to SCSS?

Using SCSS, I have the power to work wonders with CSS: @for $i from 1 through $total-items { li:nth-child(#{$i}) { animation-delay: .25s * $i; } } I am currently developing a React App that utilizes styled components. Is it possible to achieve th ...

What is the process for editing or importing CSS within a React project?

I'm a beginner in React and I am encountering an issue with CSS not loading properly. I followed the tutorial for importing it, but it seems like there might be a better way to do it now as the tutorial is outdated. Below is my code, I would appreciat ...

The grid is evenly populated with icons

Is it possible to evenly distribute the icons by only using CSS? I'm aiming to achieve a result similar to this (unfortunately, I can't post images due to my lack of reputation). You can find an example solution that uses JavaScript here: _htt ...

Whenever I include an onClick event to a div element, the entire webpage fails to display

Currently taking on the task of developing a seat booking website. I am encountering an issue with adding an event listener to a particular div element, which should trigger a function to store the value of the div. However, upon implementing the onClick e ...

"Discover the process of incorporating two HTML files into a single HTML document with the help of

I successfully created both a bar chart and a pie chart using d3.js individually. Now, I am trying to load these charts into another HTML file using jQuery. $(document).ready(function() { console.log("ready!"); $("#piediv").load("file:///usr/local ...

Having Difficulty Formatting HTML Input in Next.js

I'm encountering difficulties when trying to style HTML form elements in Next.js. I've been unsuccessful in applying CSS using a simple class name from the imported stylesheet, but have managed to achieve some success with inline styling by using ...

What causes the disparity in functionality between simple html and css in an Angular 2 project compared to a vanilla html website?

When incorporating the following html/css into a new Angular project created with Angular CLI using 'ng new ProjectName', I encountered issues. Despite adding the CSS to app.component.css or styles.css and the HTML to app.component.html, the Angu ...

How do you use CSS to replace an HTML "rules" attribute?

When publishing to HTML using the DITA Open Toolkit, certain inline table attributes are automatically applied such as frame="border" and rules="all". I am facing an issue where I need to override the "rules" attribute for table cells using CSS styles. Wh ...

Effortlessly adjust item width in CSS Grid

I am currently utilizing CSS Grid to showcase various tags. If a tag happens to be quite large, with a width exceeding 150px, I would ideally like that specific item to expand across multiple columns as necessary. For instance, in the visual representation ...

The appearance of a <div> element results in a border being applied to a different element

When hovering between the two borders, an undesirable (albeit very small) border appears around them. Can anyone assist me with this issue and explain why it is happening? I have attempted to set a transparent border on each element but without success. R ...

Ensure that the horizontal navigation items are equally spaced apart

I've managed to align my longer navigation bar items horizontally instead of vertically, but I'm struggling to evenly space them alongside the shorter items within the container. Despite trying various solutions found through research, I have not ...

Keep scrolling! There's no need to worry about reaching the end of the page and having to start over

I'm experiencing an issue where scrolling only works once when the page is initially loaded. I need it to be able to repeat from the beginning each time. <div class="content"> <div class="next-section blue">First Section</div> & ...