What is the best way to design versatile div containers that combine the float property with fluid dimensions?

I am attempting to achieve a specific layout where the width of the content_container extends up to the right side of the screen and dynamically adjusts based on whether the expandable pane is collapsed or expanded. Applying width: 100% to .content_container causes it to exceed the screen width, resulting in an unnecessary scrollbar and causing it to shift under the expandable pane. Additionally, the height of the expandable_pane does not reach the full height of its parent, whereas the content_container does.

It is clear that there are concepts I am struggling to grasp at a fundamental level, especially regarding different display types and behaviors. Any assistance in resolving this issue would be greatly appreciated.

$(document).ready(function(){
    $("#expandable_pane").click(function(){
    if(this.className.search("collapsed") != -1){
        this.className = this.className.replace("collapsed", "extended");
    } else {
        this.className = this.className.replace("extended", "collapsed");
    }
  })
})
.expandable_pane{
  float: left;
  box-shadow: 1px 1px 10px 1px rgb(98,98,98);
  overflow: hidden;
  white-space: nowrap;
  height: 100%;
  padding: 2px;
  transition: width .5s;
}

.expandable_pane.collapsed {
  width: 10px;
}

.expandable_pane.extended {
  width: 500px;
}

.flex_container {
  height: 300px;
}

.content_container{
  float: left;
  padding-left: 10px;
  height: 100%;
}

.content_pane {
  padding: 10px;
  box-shadow: 1px 1px 10px 1px rgb(98,98,98);
  height: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="flex_container">
  <div class="expandable_pane collapsed" id="expandable_pane">
    Menu Icons/Links would go here.
  </div>
  <div class="content_container">
    <div class="content_pane">
      Information for page here.
    </div>
  </div>
</div>

Answer №1

Your code is almost there, but there are a few adjustments to be made. To start, ensure that your .flex_container class includes display: flex. Additionally, for the container to fill up the remaining space, it must be able to flex. By applying flex: 1 100px to the container using shorthand properties, you instruct it to flex-grow: 1 with a flex-basis of 100px. With the use of flexbox, there is no need for float: left in this particular case.

Experiment with different values to gain a better understanding of how flexbox functions, and I recommend checking out the MDN articles regarding this property. MDN Flex

$(document).ready(function(){
    $("#expandable_pane").click(function(){
    if(this.className.search("collapsed") != -1){
        this.className = this.className.replace("collapsed", "extended");
    } else {
        this.className = this.className.replace("extended", "collapsed");
    }
  })
})
.expandable_pane{
  box-shadow: 1px 1px 10px 1px rgb(98,98,98);
  overflow: hidden;
  white-space: nowrap;
  height: 100%;
  padding: 2px;
  transition: width .5s;
}

.expandable_pane.collapsed {
  width: 10px;
}

.expandable_pane.extended {
  width: 500px;
}

.flex_container {
  display: flex;
  height: 300px;
}

.content_container{
  padding-left: 10px;
  flex: 1 100px;
  height: 100%;
}

.content_pane {
  padding: 10px;
  box-shadow: 1px 1px 10px 1px rgb(98,98,98);
  height: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="flex_container">
  <div class="expandable_pane collapsed" id="expandable_pane">
    Menu Icons/Links would go here.
  </div>
  <div class="content_container">
    <div class="content_pane">
      Information for page here.
    </div>
  </div>
</div>

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

Reignite the dynamically configured fancybox

Encountering an issue with reopening a dynamically created fancybox. The process involves initiating an AJAX request to retrieve image information, preloading the images using jQuery, and then creating a fancybox instance upon successful preload. After cl ...

Need a hand with ajax?

Recently, I've been having issues with a PHP script that packages files into a zip based on user input. Unfortunately, the server occasionally errors out and causes all the form data to be lost. To prevent this from happening in the future, I was info ...

Setting up React Router in a nested directory with a flexible route structure

As a newcomer to react router, I am seeking guidance on setting it up in a specific scenario. Imagine we have a PHP application running on 'http://www.example.com'. Within this setup, there is a react application located at 'http://www.examp ...

How can I make arrays of a specific length and populate them in JavaScript?

For instance: I have over 100 locations in a single array, each with latitude and longitude values. I need to use these locations with the Google distance matrix API to find nearby shops for my users. The issue is that this API can only handle 25 destinat ...

Efficiently update a multi-step form using Ajax and jQuery by adding new content without needing to reload the

Is it possible to create a multistep form on a single page without reloading the div with content from a PHP file, but instead appending it below? Here is my current progress: $(document).on('submit', '#reg-form', function(){ var ln = ...

Challenges of relative positioning with dynamic height based on content

Hello! I'm trying to achieve this https://i.stack.imgur.com/Q6lXP.png In this case, there are 3 divs. The top one will have a width of 100% and a height of auto, with relative positioning. The second div is similar, but I plan to add some dummy text ...

Tips for sending php data to javascript efficiently

I'm wondering about the best way to retrieve HTML table rows and display the values on another page upon clicking a button. Ideally, I would like to store these variables in a session for future use. Any advice on how to proceed? ...

What sets apart window.location.href from this.router.url?

I'm curious about the various methods of obtaining the current URL in Angular. For instance: this.router.url My main question is: What advantages does using this.router.url offer over simply using window.location? Could someone kindly provide an exp ...

RequireJS is timing out while loading the runtime configuration

I keep encountering a load timeout error with my run-time configuration, specifically with common.js. Although I have set the waitseconds value to 0 for files loaded from common.js, the loadTimeout issue persists for common.js itself. index.html <scr ...

Creating Knockout Markup within MVC 3

We're in the process of developing a new infrastructure for our MVC client to minimize the need for extensive Javascript coding, especially since most of our developers are primarily working on desktop applications. One approach I've taken for o ...

Setting up PostgreSQL database integration with Node.js

I want to remove certain entries from a PostgreSQL database based on creation/expiry dates, but I only want this to happen when the Node server first starts. Currently, I have added the line DELETE FROM ....db WHERE date <= CURRENT_DATE to the main r ...

Issues with Bootstrap Toggle Button functionality

I encountered a navbar error while working on my Django Project. After adding a few script tags, the navbar started to move down but did not return back to its original position. It worked fine before. By commenting out some script tags, it began to work a ...

Linking the User Interface to the Controller and Database

My UI requires a text field where users can input the streamId (e.g. 1, 2, 3) and then click 'ok' to display a table on the screen from the database based on the streamId value. ...

Looking for a way to transfer the value of a variable to a PHP variable using any script or code in PHP prior to submitting a form?

Within this form, the script dynamically updates the module dropdown list based on the selected project from the dropdown box. The value of the module list is captured in a text field with id='mm', and an alert box displays the value after each s ...

What are some techniques for concealing a CSS transition beneath another element in both directions?

Witness the magic in action! By clicking on the black box below, a larger black box will gracefully emerge from beneath the sidebar. While it may not be as clear in jsfiddle, rest assured that this effect is more pronounced in browsers. Thanks to some clev ...

Align the text vertically in a Bootstrap button

Can anyone lend a hand with vertically aligning text in a Bootstrap button? When I use the align-middle class, the text is aligned as desired. However, if I use the align-top class, the text remains top-aligned no matter what I do. Any suggestions? Here& ...

How can we use Cypress to check if we are at the final slide in the presentation?

I am facing a challenge with multiple slideshow files that contain varying numbers of slides. Some have 10 slides, while others have 80 slides. My goal is to test every slide by using the forward and backward arrow buttons for navigation. Currently, I am c ...

Leverage vuejs' this.$refs to work with multiple elements at once

I am working with 4 select elements: <div class="form-row"> <div class="form-group col-3"> <label for="stateSelect">Status</label> <select v-model ...

Class with an undefined function call

Currently, I am working with angular2 and TypeScript where I have defined a class. export class Example{ //.../ const self: all = this; functionToCall(){ //.. Do somerthing } mainFunctionCall(){ somepromise.then(x => self.fu ...

Exploring the power of intercepting response.send() and response.json() in express.js

Imagine having various instances where response.send(someData) is utilized. What if you wish to implement a universal interceptor that captures all .send functions and modifies someData? Is there a method within express.js to achieve this, such as hooks, ...