Adjusting a div's height to accommodate its content when it surpasses the original height

I'm working with some html/css code and I have a specific requirement. I want the height of the .inner element to adjust based on its content, only if it exceeds the default minimum height that I've defined in the code. Currently, the code doesn't allow the .box elements to expand beyond the initial height of .inner, which is not what I want. I suspect this issue may be related to the use of flex. If I remove display:flex; from .inner, the boxes can stretch beyond the initial height, but then .inner itself doesn't adjust to fit the content. I want .inner to expand when necessary, while still using either display:flex; or display:grid; for layout, as specified in my code. How can I achieve this flexibility in the design?

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.header {
  width: 100%;
  height: 70px;
  background-color: steelblue;
}

.container {
  width: 100%;
  height: calc(100vh - 70px);
  padding: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
}

.inner {
  width: 95%;
  height: 100%;
  background: steelblue;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.box {
  width: 200px;
  height: 400px;
  background-color: burlywood;
  margin: 10px;
}
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <link href="style.css" rel="stylesheet" />
    <title>Static Template</title>
  </head>
  <body>
    <div class="header"></div>
    <div class="container">
      <div class="inner">
        <div class="box"></div>
        <div class="box"></div>
        <div class="box"></div>
      </div>
    </div>
  </body>
</html>

You can view the complete code in action on codesandbox

Answer №1

To establish the default minimum height, modify the height attribute to min-height within the .container element.

The current definition in .container for the height property is causing the lack of scalability.

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 concept of recursion in AngularJS directives

I developed a unique custom directive. angular.module('menu',[]) .directive('MenuDirective',function(){ return{ restrict:'E', replace:'true', scope:{ m ...

There is no CSS styling present

I have a webpage where I want to display a modal overlay when a user clicks on an image or link. Initially, the modal is hidden and empty using this HTML: <!--// MODAL: ITEM PROFILE //--> <div id="profile" class="modal" style="visibility: hidden" ...

What function does the sx prop serve in Material UI?

<Container style={{ margin: "10px" }}> <Article post={post} setCurrentId={setCurrentId} /> </Container> <Container sx={{ margin: "10px" }}> <Article post={post} setCurrentId={setCurrentId} /> </Cont ...

Troubleshooting: Bootstrap interfering with external CSS file and causing errors

Attempting to utilize Bootstrap for the design of my website, I encountered an issue when trying to implement an external CSS file named "mycss.css". Unfortunately, it seems to not be functioning properly at all. Both the file, "mycss.css" and index.php ar ...

Tips for avoiding background-image zoom on mobile browsers when stacking elements vertically:

Within my ReactJS application, I have implemented a feature where elements are added vertically from top to bottom when the "Post" button is clicked. https://i.sstatic.net/KwPYV.jpg These elements display correctly on both mobile and desktop browsers. Ho ...

Exploring Cross-Cultural Integration in the World of HTML5

Is it possible to customize the error messages in HTML5 or do they automatically adjust based on the browser's language? For instance: <!DOCTYPE HTML> <html> <body> <form action="demo_form.asp" method="get"> ...

Is window.getComputedStyle not functioning as anticipated?

Here is a function I created to determine the width and height of a text: function size_calculation(word,fontSize) { const div = document.body.appendChild(document.createElement('div')); div.textContent = word; div.style.cssText = ` fo ...

Importing Data from Wordpress JSON Feed to Create a Table

Struggling with organizing my data into a table, as each row is currently generating a new table. Utilizing the JSON Content Importer with the following code: ...

The Bootstrap Navbar causes the window to shift when it collapses

Everything described above takes place on mobile screens. The navbar code is as follows: <nav class="navbar navbar-dark sticky-top navbar-expand-lg"> <div class="container-fluid"> <a class="navbar-brand&q ...

Changing the color of a RangeSlider dynamically using JavaScript

After dynamically creating a range slider using the provided JavaScript code, I encountered an issue when attempting to change the color of the selected portion in the slider. Despite trying to do so with additional JavaScript code, it's not working a ...

instructions for automatically opening the panel when the page loads

check out the link HERE, you'll notice that on page load the panel remains hidden. I'd like to have one of the panels open by default when the user visits the page. Can someone assist me with this, please? ...

Inject HTML content with headers using PDO in PHP

With the power of PHP PDO: I want to generate an HTML table (including thead and tbody) by querying a MySQL database using a select statement. This will be done dynamically, only requiring basic credentials and the name of the table. ...

``To ensure Google Maps fills the entire height of its parent div, set the

Is there a way to display a Google Map at 100% of the parent div's height? I've noticed that setting the height to 100% makes the map not visible, but if I use a pixel value for the height, the map displays correctly. Are there any tricks or solu ...

Could you clarify that for me?

Let's take a look at the function isIsogram(str) which checks if a string is an isogram. An isogram is a word or phrase in which no letter occurs more than once. The code snippet for this function can be seen below: We are particularly interested in ...

Instructions on how to create a horizontal scrolling div using the mouse scroll wheel

I need help with scrolling a div horizontally using the mouse scroll button. My div does not have a vertical scroll and I would like users to be able to scroll horizontally. Can anyone provide guidance on how to achieve this? ...

Is there no method to capture the message "Encountered an unexpected URL from the web process:"?

Currently, I am in the process of converting an Objective-C application to Swift using WKWebView instead of UIWebView. This app primarily showcases local content. Initially, I had no issues displaying the first webpage in WKWebView. However, when I try to ...

What is the method for creating transparent punch-through text using HTML and CSS?

I'm working with a div that has a css property of background: rgba(0, 0, 0, 0.85);. In the center of this div is the title of the page. I want to achieve a see-through effect for the title (knockout, punch-through, whatever term you prefer - essential ...

What causes the ion-fab-button to not remain fixed within the Ionic 4 popover?

I am currently working on an Ionic 4 application and have implemented a popover feature. Within this popover, I want to include an ion-fab-button that should remain fixed in the top-right corner of the popover. The snippet of HTML code I have written for ...

Updating the outline of an OutlinedInput component using React's material-ui library

Just a heads up: this is a unique question, not a duplicate of How to change outline color of Material UI React input component? I'm having trouble removing the outline on hover or focus with material-ui (React). I need this input to display a red bo ...

What is the best way to ensure that multiple SVG illustrations render smoothly while scrolling?

I created a layout of SVG line charts using the d3.js library. Each line chart is contained within its own <svg> tag inside a wrapper div structured like this: <div id="main-container" style="overflow-x: scroll"> <div class="wrapper-di ...