The div has extra white space at the bottom due to the Hide/Show content feature

Having trouble stretching a scrolling div to 100% of its parent container's height? The Hide/Show content feature is causing whitespace at the bottom of the div.

Check out the jsfiddle here: http://jsfiddle.net/fkvftff2/1/

LATEST UPDATE: The issue arises when resizing the window and clicking the hide button, leaving white space at the bottom of the div.

The culprit seems to be the toggle button. Although display block and display hidden hide the white div content, it still affects the div by creating a white space at the bottom.

If you scroll down, my goal is to expand the green scrolling div to fill the entire height of the parent container, regardless of stretching, or hiding/showing content.

Here's the relevant html code:

    <!--Center-->
    <div class="center">

     <!--Feed Content-->
     <div id="feed-content">
     <div id="networkfeed" class="feedpagetab activefeed">

     <input type="checkbox" id="filterbutton" role="button">
     <label for="filterbutton" onclick=""><span class="filterswitch">Show Me</span><span class="filterswitch">Hide Me</span> 
      </label>
                <br />
                <br />
      <div class="borderline"></div>

       <section class="filtercontent"></section><!--Filtercontent ends here-->

        <div id="contentSection">
        <div id="content">Lorem ipsum dolor sit amet...ex omnis vocibus scriptorem.</div><!--End Content-->             
         </div><!--End Content Section-->



      </div> <!--End Network feed-->
    </div><!--End Feed Content-->
</div><!--End Center-->

Below are the pertinent css styles:

.center {
    overflow:hidden;
    min-height:100%;
    float:none;
    background-color:#FFF;
    color:#999;
    position:relative;
}

#contentSection {
    overflow-y:scroll;
    position:relative;
    display:inline-block;
    background-color:green;
}
/*----- Show me Button-----*/
 ... (more CSS styles) ...

The javascript below is used for resizing the scrolling div:

 ... (javascript code for resizing) ...

As demonstrated in the fiddle, when you vertically adjust the div and toggle the content visibility, a whitespace appears at the bottom of the scrolling area. My objective is to eliminate all whitespace within the scrolling div region so that it occupies 100% of the available height without any gaps.

Your assistance is greatly appreciated!

Answer №1

It appears that there is an extra div in your code. Consider removing #contentSection and consolidating its contents within the #content div.

If you want to make the entire text disappear with a button click, perhaps modify the style of the content text. For example, change opacity:1 to opacity:0 when the button is clicked.

Answer №2

In regards to the feed and center, I have made some minor edits to your code and included a toggle feature. Take a look at my Fiddle.

My focus was primarily on your content section. Here is the updated HTML for it:

  <button onclick="toggleContent()">Toggle Visibility</button>

  <div id="contentWrapper">
    <div id="content">
      text goes here. longer version in JSFiddle
     </div>             
  </div>

The corresponding JavaScript function is as follows:

function toggleContent() {
  // Get the DOM reference
  var e = document.getElementById("content");
  // Toggle 
  e.style.opacity == "1" ? e.style.opacity = "0" : 
  e.style.opacity = "1"; 
}

This function essentially switches the opacity of the content when the button is clicked. Here is the CSS styling for your element (you can use border-top instead of a div for a top border, and to center, create a container with width=100% and apply margin:auto to your centered class):

#contentWrapper{
 width:100%;
 position:relative;
 border-top:1px solid black;
 padding-top:10px;
 margin-top:10px;
}

#content {
 overflow-y:scroll;
 background-color:green;
 height:400px;
 width:500px;
 margin:auto;
}

I hope this helps clarify things!

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 process of integrating Tailwind elements into NextJs version 13

Can anyone help me integrate Tailwind elements into my NextJs project using JavaScript instead of TypeScript? I tried following the documentation, but the navbar component's expand button doesn't work. It seems like all components are having some ...

Looking for a jQuery plugin that helps with form alignment?

In a blog post comment, I came across an interesting jQuery form alignment plugin: jQuery.fn.autoWidth = function(options) { var settings = { limitWidth : false } if(options) { jQuery.extend(settings, options); }; ...

Is the sliding navigation glitching due to the video background?

Currently, I am in the process of developing a website with a captivating full-page video background. The nav menu gracefully slides out from the left side using jQuery UI when users scroll down to view the site's content. To view the work-in-progres ...

Which tool is best for comparing and minimizing duplicated CSS style sheets?

In my current project, I am working with 2 CSS files. The first one serves as a "default" style sheet that is used in all websites created from the same templates. The second file contains the specific styles for our application. Both of these files are in ...

Guide to setting a dynamic print style without affecting the screen media

In my report, there is a details section below. The screen provides instructions to view the details with a button that toggles the list's visibility. When printing the report, I only want the instructions to show if the list is visible. If the list ...

Using CSS to create sleek all-black Flaticons

After trying various solutions, I am still unable to fix this issue. I downloaded some icons and in the demo, they all appear as they should, with a more colorful aesthetic. Here is what the icons should look like: However, this is how the icons actually ...

Both JOINs are being performed on the identical table

Currently, I am working on a website that displays soccer scores with two teams and two scores stored in my database. Below is the code I am using: <?php $result = mysql_query( "SELECT * FROM resultat LEFT JOIN brukere ON resultat.do ...

Do not display the outcome of the unsuccessful Ajax registration attempt

I am facing an issue with my AJAX post method. When the account is successfully created, it should alert "account successfully created", but if it already exists, it should alert "account already exists". However, the problem is that it still alerts the sa ...

Maximum number of days that can be selected with Bootstrap Datepicker

I currently have a datepicker set with the multidate option and I am looking to specify a maximum number of days that users can select, say 5 days. Once a user has selected 5 days, any additional days should become disabled dynamically. How can this be a ...

The application is resetting when the "$http" method accesses the initial ADAL "protected" URL for the first time

I have created a page inspired by the Angular SPA ADAL sample which can be found here Upon returning from the Microsoft login page and accessing my API secured with AAD, the angular .config() function is called multiple times. This causes issues with upda ...

Issue Alert: React - Material-UI version 6 does not support renderInput Property in DesktopDatePicker

Exploring the integration of React with Material UI Version 6 Library, I am looking to personalize the appearance of the rendered Input. In the previous version, Version 5, there was a property called "inputProp" for DateTimePicker. However, this feature ...

The {shade} of the code has been modified within brackets

Ever encountered your code's colors abruptly changing to red and green in the middle of an HTML page? My editor is Brackets, and while it doesn't pose any issues, it's really bothersome and makes the code difficult to read: Take a look at t ...

Align a series of divs in the center with variable width and height

I have a dilemma with my large div that contains multiple thumbnails. I am looking to center the thumbnails within the div and have the overall div centered on the page. Additionally, I want the width of the div to be flexible so that all thumbnails can be ...

"Unexpected compatibility issues arise when using TypeScript with React, causing errors in props functionality

Just the other day, my TypeScript+React project was running smoothly. But now, without making any changes to the configurations, everything seems to be broken. Even rolling back to previous versions using Git or reinstalling packages with NPM does not solv ...

Expanding the <li> elements to create a wide horizontal navigation menu that fits within a 960 grid layout with 12 columns

I'm having trouble making the individual "li" elements inside the "nav" element stretch to fill a 600px space defined by the class "grid_8" in the HTML. I've tried setting width:100%; for the nav, li { width: 100%;} and various other solutions wi ...

Group in group, glitch in outdated browser

Facing an issue with IE6 while writing HTML/CSS code. I am looking to create dynamic divs using classes: Here is a simple example (not real-project code): .top {width: 50px;} .top.selected {background: #f00;} .mid {width: 114px;} .mid.selected {backgrou ...

Unable to Retrieve JSON Output

PHP Code: $contents = ''; $dataarray = file('/location/'.$_GET['playlist'].''); //Loading file data into array $finallist = ''; //Extract Track Info foreach ($dataarray as $line_num => $line) //Loopin ...

What could be causing the lack of color change in my boxes even after confirming the prompt?

function changeColor() { if (confirm("Press a button!") == true) { if(this.style.backgroundColor == "white") this.style.backgroundColor = "yellow"; else if(this.style.backgroundColor == "yellow") this.style.backgroundColor = "red"; else i ...

TreeView Filtering

I have encountered an issue while trying to utilize a treeview filter. Below is the method I have created: var tree = [{ id: "Tree", text: "Tree", children: [ { id: "Leaf_1", text: "Leaf 1", childre ...

Working with JSON data and extracting specific information within the grades

Here is a JSON data structure that contains information about a student named Alice and her grades in various courses: { "student": [{ "cert_id": "59826ffeaa6-b986fc04d9de", "batch_id": "b3d68a-402a-b205-6888934d9", "name": "Alice", "pro ...