Adjust size of container div once ajax call is complete

I am currently facing an issue with a webpage where I am using ajax to load a Twitter feed. Below is my HTML and jQuery setup:

<body>
<div class="document-wrapper">
    <div class="document">
        <div class="content">   
                <div class="right-column">
                    <h2 class="twitter-header">Recent Tweets</h2>
                    <div class="twitter-feed" id="feed">
                    </div>
                </div>
<script type="text/javascript">
   $(document).ready(function () {
        $('#feed').load("/Home/Twitter", '', showNewContent)
   }); 
   function showNewContent() {  

    }  
</script>
</div>(document)
<div class="document-end"></div>

The content is loading correctly into the feed div, but there is an issue with container resizing causing poor overflow. Although all divs have height:auto; set, it doesn't seem to work. Setting a min-height on the document class resolves the issue slightly, but this is not the desired solution.

Upon closer inspection, it seems that the document div is resizing but fails to push everything below it down when it does so. As a result, the page footer remains in place while new content gets rendered behind it and becomes unselectable.

Is there a way to ensure proper resizing of all elements after the ajax call?

Edit: Here's some relevant CSS:

.footer-wrapper,
.document-wrapper {
width       : 960px;
margin      : 0 auto;
position    : relative;
height      : auto;
}

.document-wrapper { background : url(background-content.jpg) top repeat-y; }

.document { 
padding : 0 35px 75px 35px;
height: auto;
}

.document-end {
height      : 39px;
width       : 960px;
margin      : 0;
background  : url(background-content-end.jpg) top no-repeat;
}

.right-column {
float       : right;
width       : 300px;
font-size   : 90%;
position    : relative;
left        : -30px;
padding     : 4px 0 0 0;
height: auto;
}

.twitter-feed 
{
height:auto;
color       : #ccc;
}

Answer №1

It seems like your elements may be lacking proper "layout". For a more fluid design, it's best not to set explicit dimensions. Divs should adjust automatically.

If you're encountering issues with child elements not taking on dimensions correctly, try adding clear: both; and float: left:

.yourDiv {
   clear: both;
   float: left; /* or right */
}

This solution usually resolves the problem in my experience.

If that doesn't work, you may need to calculate the combined heights of the children and set the container to that height manually.

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

Blending an HTML jQuery toggle

Is there a way to make the current headline fade out while simultaneously fading in a new one when switching to the next div using a jQuery .html switch? Check out the codepen example: https://codepen.io/balke/pen/JpNNve $(window).scroll(function() { ...

Permanently remove the span tag and any associated text from the HTML document

Currently, I am working on a project that involves numerous page numbers marked using the span class. Below is an example of this markup: <p>Cillacepro di to tem endelias eaquunto maximint eostrum eos dolorit et laboria estiati buscia ditiatiis il ...

Guide to fetching JSON data following an AJAX submission of a form to the database

I am having trouble with my code that inserts data into a database using Ajax. I want the client side to automatically retrieve a callback JSON after saving the data to the database. However, the JSON is not showing in the console. Can anyone help me? Thi ...

Troubleshooting Cross-Origin Resource Sharing (CORS) problem in Jquery

When using AJAX post from jQuery to call two REST services on different domains for business logic, a CORS issue arises. By setting crossDomain: true in my AJAX call following Google references, it works fine without specifying headers. However, if I inc ...

Access the designated hyperlink within the table row

Currently experimenting with Selenium Webdriver in Firefox and also looking to test in IE8. Below is the structure of my HTML: <table id="table"> <tbody> <tr> <td>Text1</td> <td><a id="assign" hr ...

CSS following a clicked event

http://codepen.io/anon/pen/GqmEAq My goal is to make the 'x' button clicked (the 'x' is created after clicking the plus sign on the menu) and then bring the dropdown back up. I have attempted: a:after:checked ~ .submenu{ max-height ...

HTML - Navbar and Sidebar Only Partially Spanning the Width

Hey there! I am trying to make my sidebar and navbar full width, but for some reason, they are not extending all the way. Can anyone help me figure out why? Below is the code I'm using: I have included an image to illustrate the issue: https://i.sst ...

Using jQuery, you can dynamically fill a field with data retrieved from two separate fields

Is there a way to automatically populate the 'Full Name' field based on what the user enters in the 'First Name' and 'Last Name' fields? For example, if the user types 'John' and 'Smith', the 'Full Nam ...

Ways to place a png image on top of a video background

How can I overlay a PNG over my background video without it appearing behind? I attempted to use z-index, but the video disappears when changing the position from relative to absolute or fixed. Here is the HTML and CSS code: <div id="page2"> &l ...

Having trouble with the option:selected function in jQuery 1.9?

Here is a query that works perfectly with versions of jQuery prior to 1.9: $("select option:contains(fish)").attr('selected', true); Unfortunately, this query does not function at all with jQuery 1.9 and newer versions. Despite searching for ...

Trouble incorporating JSON in JQuery and MVC

I am attempting to trigger my controller using JavaScript and jQuery. Below is the jQuery code I have: <script type="text/javascript> $('form').submit(function (e) { e.preventDefault(); $.ajax({ type: "POST", url: $(this).attr(" ...

The design problem arises from using jQuery to dynamically prepare the table body at runtime

The table row and data are not appearing in the correct format. Here is a link to the problem on Fiddle: http://jsfiddle.net/otc056L9/ Below is the HTML code: <table border="1" style="width: 100%" class="eventtable"> <thead style="color: b ...

Having trouble hiding the message "Not found" with ng-hide and filters in AngularJS

I am currently working on incorporating instant search functionality with filters in AngularJS. My goal is to have the "Not Found!!" message displayed when the filter results in an empty array, indicating that no matches were found. However, I have encou ...

Ways to create a border button with a matching width to the text above using CSS

Is it possible to style a border button in CSS so that the width matches the text above? I am trying to achieve a clean look for the navigation selected text, where the border-bottom aligns with the text above. Here is an example of what I have attempted ...

Input field offering various autosuggestions based on category and specific criteria

Can anyone provide some insight on implementing multiple autosuggestions during a search process? The search string comprises a Category, optional Criteria, and value. For example: Category.Criteria I attempted to use jQuery with autocomplete, and the fi ...

Access information via ajax from a php script

I am currently working on an AJAX code that sends data to PHP and then receives data from PHP... function updateDatabase(syncData){ $.ajax({ type : 'POST', async: false, url : 'php/syncData.php', ...

Troubleshooting a problem with jQuery: alter background color when checkbox is

I recently created a script to change the background color when a radio button is selected. While it works for checkboxes, I noticed that when another radio button is selected, the previous one still remains with the selected color. <script type="text/ ...

Tips for extracting text from a textarea while retaining newline characters:

When using jquery, my goal is to retrieve the text from a textarea element with new lines represented as \n instead of br tags. However, I encountered an issue where Firefox debugger does not display the \n or br characters when I select it and r ...

Tips for making a bookmark for your iframe content

Within this HTML code, there is a list element with the ID "about_ma" and an iframe named "page" that is initially hidden. <div id="navigation"> <ul id="nav"> <li id="about_ma"><a href="index1.php?name=about.php">Ab ...

The secondary ul in the Boostrap navigation is not reacting to the custom CSS borders as expected

I am currently facing an issue with my bootstrap navigation related to the border-bottom: **attribute** when it comes to a secondary ul in a drop-down menu. My goal is to apply border-bottom: medium black solid or something similar to the visible part of ...