"Using jQuery, make a div disappear by setting its height to auto

I recently started exploring responsive web design and encountered an issue. I believe it might be something small, but I'm having trouble resolving it. I have a div called body_main_wrapper with child divs Functions_Panel_Wrapper and Function_Page_Wrapper floating to the left. The height of these parent and child divs is calculated at runtime using jQuery. My goal is that when the viewport width is less than 786 pixels, the child divs should appear with 100% width and auto height.

Although I attempted to set the height to ("auto") using else if (viewport width < 786), my child div disappears...

jQuery plugin

(function ($) {


$.fn.adjust_BodyMainWrapper_Height = function () {

    $(window).bind('load resize', function () {

        var viewport_height = $(window).height();

        var viewport_width = $(window).width();

        var Wrapper_Height = (viewport_height - ($(".footer_wrapper").height()) - ($(".navbar-header").height()));

        //height of footer - height of header - height of current viewport// 
        $("#body_main_wrapper").css("height", Wrapper_Height + "px");

        if (viewport_width > 768) {

            //adjust height of Functions_Panel_Wrapper 
            $("#Functions_Panel_Wrapper").css("height", Wrapper_Height - 1 + "px");

            //adjust height of Function_Page_Wrapper 
            $(".Function_Page_Wrapper").css("height", Wrapper_Height - 1 + "px");
        }
        else if (viewport_width < 768) {
            $("#Functions_Panel_Wrapper").height("auto");
        }

    });
};

})(jQuery);

html

 <div class="body-content">

    <!--*************************** Main Body ***********************************-->

    <div id="body_main_wrapper">
        <!--Functions Panel Wrapper (left-side)-->
        <div id="Functions_Panel_Wrapper">
            <a>functions lists.....</a>
        </div>

        <!--Functions Page Wrapper (right-side)-->
        <div class="Function_Page_Wrapper">
            @RenderBody()
        </div> <!--end Function_Page_Wrapper-->
        <hr />
    </div> <!--end body_main_wrapper-->

        <!--*************************** Footer ***********************************-->
        <div class="footer_wrapper">
            <footer>
                <div class="container">
                    <div class="footer_Title_Wrapper">
                        <p>&copy; @DateTime.Now.Year - My ASP.NET Application</p>
                    </div> <!--end footer_Title_Wrapper-->
                </div> <!--end container-->
            </footer>
        </div><!--end footer_wrapper-->
    </div> <!--end body-content-->

CSS

#body_main_wrapper{
width:100%;   
margin-top:-19px; 
background-color:grey;
}

#Functions_Panel_Wrapper{
width:20%;
float:left;
background-color:red;

}

.Function_Page_Wrapper{
width:79%;
float:left;
margin-left:1%;
background-color:pink;
}

@media (Max-width: 768px) {

 #Functions_Panel_Wrapper{ width:100%; float:none; }

 .Function_Page_Wrapper{ width:100%; float:none; margin-left: 0; }

}

jsfiddle: http://jsfiddle.net/U47K9/

Answer №1

When all the contents of an element are floated, it will have a default height of 0 (only non-floated children will determine the height). If the height of the children is determined by their parent, they will also be set to a height of 0.

#wrapper_main_body {
    *zoom: 1;
}

#wrapper_main_body:after {
    clear: both;
    content: " ";
    display: table;
}

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

Stylish tag colors in ExtJS 3 SuperBoxSelect

My SuperBoxSelect element is being populated from a remote store. I am looking to assign a different color to each tag when it is selected. The color value for each tag comes from the store. Currently, I am attempting to achieve this by using the followi ...

Display a Bootstrap Popover upon hovering over an alert message

I have created a custom notification window using the bootstrap alert class. The string has been trimmed for display, but I want the full message to appear in a popover when the user hovers over it. Below is the code snippet used for displaying notificatio ...

Content is positioned to the left in a horizontal layout without a set width

I am currently assisting a friend with the development of her website. While I consider myself somewhat of an amateur in web design, I usually manage to overcome challenges by dedicating hours to searching for solutions online. However, this time I have no ...

Issue with React Bootstrap Scrollspy not functioning correctly on Android mobile browsers

I am currently using bootstrap 5.2.2 within React to add Scrollspy functionality to my menu. The Scrollspy feature functions correctly in web browsers on laptops and iPhones. However, on Android mobile devices, the Scrollspy fails to update the active lin ...

What is the proper method for filling a custom shape that has been created in Canvas?

I am attempting to create a custom shape, but I am facing an issue where using moveTo prevents me from filling it. Is there any method to determine points on the screen to fill a shape? Or should I use or draw another real shape in the same layer block? T ...

Determine the total value of various dynamic elements by utilizing jQuery/Javascript for calculation

I am currently working on a project that involves a dynamic list of products in a cart. I need to calculate the total price of all the products in the cart, but I am having trouble figuring out how to access and calculate the values from these dynamic elem ...

Retrieve data from an ASP.NET Web API endpoint utilizing AngularJS for seamless file extraction

In my project using Angular JS, I have an anchor tag (<a>) that triggers an HTTP request to a WebAPI method. This method returns a file. Now, my goal is to ensure that the file is downloaded to the user's device once the request is successful. ...

Guide on placing an <img> within a navigation bar

I am currently working on a Bootstrap 4 navbar that includes both a logo and text in the navbar-brand section. However, I am facing difficulties in positioning the brand-logo and text accordingly. <!doctype html> <html ...

Pause until the existence of document.body is confirmed

Recently, I developed a Chrome extension that runs before the page fully loads by setting the attribute "run_at": "document_start". One issue I encountered is that I need to insert a div tag into the body of the webpage as soon as it is created. However, a ...

Is there a way to integrate jQuery validation on an ajax form that queries the database for a specific value in Ruby on Rails?

Recently, I added a phone/sim checker to my system. Users need to input their phone number in the first form field. If the phone number is in the database, a message about finding the phone number will be displayed. If not, the form switches to inputting t ...

Error in WebGL rendering: attribs are not configured properly

Below is the code for my vertex shader: attribute vec3 aVertexPosition; attribute vec4 aVertexColor; attribute float type; uniform mat4 uMVMatrix; uniform mat4 uPMatrix; varying vec4 vColor; void main(void) { gl_Positi ...

Troubleshooting innerHTML in jQuery

<script> $(document).ready(function() { var msg='{"ui":{"callData":[{"Title":"Caller Details", "Text":"<html><body><table border=&quot;1&quot;><tr><td>Caller details content</td></tr>< ...

When you open the responsive navigation bar, it automatically closes

After creating a website some time ago, I decided to make it responsive by adding a menu. However, I encountered an issue where the menu bar opens but immediately closes after showing the entire list. Here is the HTML code for the menu: <!-- start men ...

Content in Tab Fails to Load due to IFRAME URL

On my web page, I have embedded an IFRAME with its src attribute set to load HTTPS content. This IFRAME is placed within a Bootstrap Nav-Tab Content, which in turn is located inside a Card element. Upon loading the webpage, I noticed that the content does ...

Discovering phrases and adjusting the hue

Is there a way to change the color of text output by the ECHO function using CSS and conditions? For instance: If I use the ECHO function to display text like this: echo ": The net value of the entire order" echo ": The gross value of the entire order" ...

Unable to populate Select2 v4.x using ajax calls

I am currently working with the latest version of select2 (version 4). I have successfully implemented AJAX requests and confirmed that the responses are coming through correctly. However, I am facing an issue where the select element is not populating i ...

Maintaining the sequence of a PHP associative array when transferring it to JavaScript via ajax

Below is the code from my PHP file: GetUserArray.php $Users = array('7'=>'samei', '4'=>"chaya", '10'=>'abetterchutia'); echo json_encode($Users); Here is the AJAX request I am using: $.ajax({ ...

Creating a dynamic dropdown menu using jQuery in conjunction with PHP and MySQL database

I am working on implementing a dynamic dropdown menu in my website to include address details such as state, city, area, and postcode. The code appears to be functioning properly when testing each component individually in the live browser. However, I enco ...

Personalizing the predefined title bar outline of the input text field

The outline color of the title in the input textbox appears differently in Google Chrome, and the bottom border line looks different as well. <input type="text" title="Please fill out this field."> https://i.stack.imgur.com/iJwPp.png To address th ...

Clicking on a link does not place the focus on the corresponding input field

My project involves creating a One Pager website with a navigation menu. I am looking to implement radio inputs that are associated with the clicked link (a) so that I can apply CSS styles to the active radio button. Currently, the CSS is applied when the ...