What's the best way to make sure a div container fills in the remaining space between elements?

How can I make the center div take up the remaining space between the left and right divs, without covering them? The contents in the center can overflow hidden if necessary.

View my code on jsFiddle

HTML

<div id=container>
    <div id=left>
        <div>first element</div>
        <div>second element</div>
        <div>third element</div>
    </div>
    <div id=right>right frame variable width</div>
    <div id=center>
        <div>first element</div>
        <div>second element</div>
        <div>third element</div>
    </div>
</div>

CSS

html,body{margin:0;}
*{box-sizing:border-box;}
#container {
    height:30px;
    white-space:nowrap;
    background-color:lightgreen;
}
#left {
    float:left;
    border:4px solid black;
    height:100%;
}
#left *{
    border:2px solid blue;
    display:inline-block;
    height:100%;
}
#center {
    float:left;
    border:4px solid black;
    display:inline-block;
    overflow:hidden;
    height:100%;
}
#center *{
    border:2px solid red;
    display:inline-block;
    height:100%;
}
#right {
    float:right;
    border:4px solid black;
    height:100%;
}

Answer №1

To fix the layout issue, simply delete the float:left and display:inline-block properties from the #center element.

Check out the demonstration here: http://jsfiddle.net/Z2x8e/8/

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

What is the easiest method to design an email subscription form that remains fixed on the top right corner of the screen?

Looking for advice on setting up a sleek email signup bar that remains at the top of the browser while users scroll and navigate through different pages. I am working with WordPress and have jquery already loaded, but have not yet worked with either. Up ...

What is the significance of the source element in Vue3's audio element?

Playing mp3 files works in Vue 2, but not in Vue3. <template> <audio src="../file_example_MP3_700KB.mp3" controls ></audio> </template> In Vue3, the code needs to be modified as follows: <template> <audi ...

Sending files to the server through HTML5

Could someone assist me with uploading a file after it has been selected using HTML5? Here's the code snippet for selecting the file: <input type="file" .... /> The input field above allows you to choose a file, but I also need help with uploa ...

Tailwind features a layout with a scrollable center and right divs, complemented by a sticky header and left

I'm currently working on a layout similar to an email or tasks interface, where the page has a fixed header and three columns. The left column is also fixed, while the center and right columns have fixed headers. Everything seems to be functioning as ...

Utilizing Dynamic URLs and Transmitting Non-User Input Data from HTML to Python via Flask

After doing some research, I discovered that data can only be sent from input forms in HTML to Python using the POST method. I am now trying to find a way to pass a value (originally stored in a dictionary passed from Python) from HTML to Python. I have t ...

What steps do I need to take to create my own Japanese tatami mat design?

Looking to design an HTML layout inspired by the classic Japanese tatami mat pattern. https://i.sstatic.net/vLUtp.png Experimented with using rowspan and colspan in a table layout, making progress until the final colspan caused things to collapse. td ...

Troubleshooting the malfunctioning of the edit record feature in Python Django when using Jquery

Scenario: My HTML table displays data for a specific user with delete and edit buttons next to each row. While the delete button functions correctly, clicking the edit button does not trigger any action despite following a similar approach. This snippet o ...

The NextRouter failed to mount

Currently, I am in the process of incorporating a search functionality into my property rental application. I have successfully added the Nextjs Router to handle the routing. However, when attempting to access localhost:3000/search, an error is encountered ...

Tips on incorporating FORM elements with tables and ensuring that data submitted through $_POST method is successfully posted

Recently, I have been encountering an issue with a simple FORM on my website. Whenever I press the SUBMIT button, nothing happens - the form seems to activate but no $_POST variables are being received. echo "<hr>1aa<br />\n"; ...

The art of controlling iframe elements with jquery

I've been researching various topics related to this issue, but I'm still unable to achieve the desired outcome. Currently, I am embedding an iframe within an HTML document like so: <iframe class="full-screen-preview__frame" id="nitseditpre ...

The PrimeNg confirmDialog is updating my navbar with some modifications

Despite my navbar working well and being fully responsive, I encountered an issue where opening a confirm dialog in the background caused the navbar width to expand to 800px even though the screen width was 1480px, creating empty space on the right side, a ...

How can one retrieve the ID value within a function using jQuery?

I am trying to implement an upload picture function along with cropper js function. However, I am facing an issue with displaying the file name even though I have declared the variable and set the input value. But when I attempt to pass and display the nam ...

Preventing Height Stretch in CSS Flex-Wrap: A Guide

Is there a way to eliminate the large gaps between box3, box1 and box4, box6? How can we ensure each box adjusts its height dynamically? .wrap { display: flex; align-items: baseline; align-content:flex-start; justify-content: space-between; fl ...

Can CSS be used to communicate to JavaScript which media queries are currently in effect?

Is there a way for Javascript to detect when a specific CSS media query is active without repeating the conditions of the media query in Javascript? Perhaps something similar to an HTML data attribute, but for CSS. For example: CSS @media (min-width: 94 ...

tips for extracting live hyperlinks by accessing hrefs

While parsing the HTML code of a webpage, I am extracting all the links mentioned as hrefs using regex. However, I have encountered a situation where certain websites, like Wikipedia, mention hrefs in the HTML code as a paraphrase. For example: The code s ...

Removing the border from a button in CSS and HTML

Looking to build a sleek and stunning website, but struggling with removing button borders. Any help would be greatly appreciated! If you'd like to check out the issue, visit this link: https://i.sstatic.net/daaec.jpg. I'm aiming for no button o ...

The mp4 video on the website will only load if the Chrome developer tools are activated

Whenever I try to play the video set as the background of the div, it only starts playing if I refresh the page with Chrome dev tools open. HTML: <div id="videoDiv"> <div id="videoBlock"> <img src="" id="vidSub"> <video preload="prel ...

Is there a way to prevent inheriting width properties? Or perhaps how can one revert back to the original width value

After installing the Thank you plugin, I noticed that the button on my test site appears to be strange. Upon further investigation, I discovered that it is inheriting #commentform textarea { width: 45%; } from my theme. While removing the width in the CSS ...

What is the best method to align a form in three columns from each side without relying on Bootstrap?

Is there a way to center the form inside a card with 3 columns on each side, so that the form appears in the middle occupying about 6 columns without relying on Bootstrap, Materialize or any similar framework? Thanks! <div class="card"> & ...

What is the best way to toggle a div and dynamically load content into it while it's open?

I am looking to create a toggle effect where a div opens, loads a page within it, and then can be closed again. My goal is to achieve this functionality with multiple links on the page. <div id="main-nav"> <div id="menu-container"&g ...