Ask Your Question
2

How can you make a div occupy the rest of the space below a div that has a height that varies?

asked 2023-05-30 16:12:58 +0000

david gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2023-05-30 16:20:02 +0000

qstack gravatar image

You can use the CSS flexbox layout to achieve this.

First, you need to create a container div that will hold both the variable-height div and the div that should occupy the rest of the space. Set the display property of this container to flex and the flex-direction property to column.

Next, set the height of the variable-height div to auto so it can adjust its height according to its content.

Finally, set the height of the div that should occupy the rest of the space to 100% and set the flex property to 1 to make it expand and fill the remaining space.

Here is an example CSS code:

.container { display: flex; flex-direction: column; }

.variable-height-div { height: auto; }

.fill-space-div { height: 100%; flex: 1; }

And here is an example HTML code:

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-05-30 16:12:58 +0000

Seen: 9 times

Last updated: May 30 '23