Three brothers and sisters - One must expand responsively while the remaining two maintain minimum content sizes

Attempting to outline the limitations at hand.

We have 3 containers named .content, .left, and .bottom, along with a resize handler that governs the available space.

  • I aim for the .container to expand as the space increases, utilizing all available area.
  • The .left container should maintain its minimum width and occupy 100% of the height, which is already achieved (excellent).
  • On the other hand, the .bottom container needs to retain its minimum height while occupying 100% of the width, which currently is not working as desired.
  • Modifying the HTML structure is not an option, given real-world constraints beyond my control.

After experimenting with various combinations of align-items: stretch and grow, I found it challenging to achieve the desired layout when the direction is set to row. Changing to a column layout would require altering the HTML structure, which is not feasible in this scenario.

.container {
  display: flex;
  flex-wrap: wrap;
  height: 20rem;
  width: 20rem;
  overflow: hidden;
  resize: both;
  border: 1px solid blue;
}

.left {
  border: 1px solid red;
}

.content {
  border: 1px solid pink;
  flex: 1;
}

.bottom {
   border: 1px solid grey;
   flex-basis: 100%;
}
<div class="container">
    <div class="left">left min content</div>
    <div class="content">should resize vertically and horizontally</div>
    <div class="bottom"/>bottom should be min content</div>
</div>

Answer №1

To address this particular situation, we can make use of the CSS properties like display: grid; to achieve the desired outcome without making any changes to the HTML structure. Here is a sample implementation:

.container {
    display: grid;
    grid-template-columns: max-content auto;
    grid-template-rows: auto max-content;
    height: 40rem;
    width: 20rem;
    overflow: hidden;
    resize: both;
    border: 1px solid blue;
}

.left {
  border: 1px solid red;
}

.content {
  border: 1px solid pink;
}

.bottom {
   border: 1px solid grey;
   grid-column: span 2;
}
<div class="container">
    <div class="left">left min content</div>
    <div class="content">should resize vertically and horizontally</div>
    <div class="bottom">bottom should be min content</div>
</div>

The approach involves defining 2 rows and columns using

grid-template-columns: max-content auto;
and
grid-template-rows: auto max-content;
. The first column occupies all the available height with max-content, while the second (bottom) column remains auto and fills up the remaining space.

Additionally, applying grid-column: span 2; on the bottom div extends its size to cover 2 rows, equivalent to 100% of the width in our case (since we have 2 rows only).

This solution should effectively address the issue at hand.

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

CSS: Caption text below image remains on same line

I am struggling with positioning a div that contains an image and a caption. My goal is to make the caption break into a new line when it reaches 95% of the width of the image. Despite my efforts, I can't seem to achieve this. The text always pushes ...

Restrict modifications in Sharepoint 2013 to text only

Can content editors be restricted to only adding text on websites? I want to prevent them from using inline styling in HTML or buttons in the editor to add styles. I'm dealing with a few rebellious editors who like to get creative with colors and sty ...

Failure of PrimeNG Autocomplete dropdown to adjust position

My experience with the PrimeNG Autocomplete plugin resulted in some conflicts. When using this style, the autocomplete drop-downs are positioned downward. Image description goes here https://i.sstatic.net/VZmAk.png If anyone knows how to resolve this is ...

How can the target pseudo-class be utilized to replace the 'active' state on navigation across several pages effectively?

Within a large application, I am managing a micro site and looking to implement tertiary navigation with an active state for pages. This involves inserting a single html blob into multiple pages. My goal is to use an active class to highlight the page in ...

What are alternative methods for creating a table layout without relying on traditional table elements?

Is there a way to eliminate tables from my code and achieve the same layout in the name of progress and learning? Here is an example of the table I currently have: <table cellspacing="0px"> <tr> <td> <img src= ...

Selecting specific categories to display on the homepage and limiting the number of images shown

<<html> <head> <meta charset='utf-8'> <meta http-equiv='X-UA-Compatible' content='IE=edge'> <title>Gallery</title> <!-- CSS only --> <link href="https://cdn.jsdel ...

Text within table cells on email appears to be shrinking on Windows Phone devices

Can anyone help me understand why Windows Phone reduces the font size when text is placed within a table cell that isn't at 100% width or nested? Below is a screenshot of a test email template I'm working on. When I sent it to a Windows Phone 8. ...

How can I apply borders to individual columns within a Bootstrap table without affecting the rows?

My attempted solution involved adding th and tfoot. However, I faced issues with applying borders to only the td elements - border was not being applied at the bottom of the table, and the thickness and color of the borders were inconsistent between column ...

Is there a workaround utilizing calc() and vh specifically for Chrome browsers?

Is it possible to find a CSS-only solution for incorporating vh in calc() functions specifically for Chrome browsers? I am trying to implement calc(100vh - 25px) as the top margin in order to make a 25px bar stick to the bottom of the page, but I am facin ...

Issues with positioning images using media queries

Can anyone help me center an img when the viewport width is 320px? I've attempted different approaches but so far, nothing has been successful. .logo { width: 55px; height: 55px; margin: 10px 0 10px 30px; float: left; } @media only screen a ...

Easy Registration Page using HTML, CSS, and JavaScript

In the process of creating a basic login form using HTML and CSS, I'm incorporating Javascript to handle empty field validations. To view my current progress, you can find my code on jsfiddle My goal is to implement validation for empty text fields ...

Maintain the image's aspect ratio by setting the width equal to the height when the height is

I am uncertain if achieving this purely with CSS is possible, but it would be ideal. I currently have an image: <img src="#" class="article-thumb"> CSS: .article-thumb { height: 55%; } Is there a way to set the width equal to the height? My g ...

Using CSS to automatically convert a table into one column layout with labels from the thead section

Is it possible to automatically create the labels for data when converting a multi-columns table into one column using CSS and taking the information from the thead section? This resource discusses how to convert a multi-column table into a single column ...

CSS PopUp positioning

Can anyone help me with applying the position top and bottom of header to the NewUser div? I've tried but it's not working. How can I add !important; to the CSS? Maybe something like $("header")!important} <div id="divNewUser" class="CreateUs ...

Looking to create a custom loader that adapts to different screen sizes

Can anyone help me make the text in my centered div responsive on my website loader? I'm new to coding and struggling to figure it out. Any assistance would be greatly appreciated! Make sure to view the full page snippet so you can see the text prope ...

Ways to style CSS for inactive checkboxes?

How can I easily change the CSS for disabled checkboxes in a grid to make them more visible for users? Technologies I prefer to use, ranked from most preferred to least: CSS JavaScript jQuery Other ...

Retrieve the hidden value buried within multiple layers of classes

I'm having trouble retrieving the value from the pickup-address class. Here is my current code. Can anyone help me identify where I might be going wrong? JS var pickupAddress = $('.timeline-item.active-item > .timeline-status > .pickup-add ...

Can a FontAwesome icon be used as a button in Bootstrap?

Hi there, I'm trying to use a fontawesome icon as a button in my code. Here is what I have so far: <!DOCTYPE html> <html lang="en"> <head> <link href="https://cdn.jsdelivr.net/npm/<a href="/cdn-cgi/l/email-protection" ...

changing the css transformation into zoom and positioning

My goal is to incorporate pinch zoom and panning using hardware-accelerated CSS properties like transform: translate3d() scale3d(). After completing the gesture, I reset the transform and switch to CSS zoom along with absolute positioning. This method ensu ...

Off-center rotation of an element - seeking solution [closed

This question has been closed. It requires additional details for debugging. Answer submissions are currently not accepted. ...