Avoid DIV from exceeding margin-bottom

Currently, I have a div with defined margins and within it, there are two other divs: one positioned on top and the other below. My goal is to make the lower div expand to fill the remaining space between the top div and the bottom margin of the main div.

Below is the current structure:

<div class="main">
    <div class="top"></div>
    <div class="bottom"></div>
</div>

CSS:

.main {
    width: 90px;
    height: 30vh;
    min-height: 225px;
    margin: 0;
    margin-left: 5px;
    margin-top: 25px;
    margin-bottom: 25px;
}

The height of .main div adjusts according to the viewheight.
.top div contains a form with a height of 220px.
The goal is for the .bottom div to occupy the empty space between the .top div and the margin set at the bottom.

I've experimented with various methods but haven't found a solution that works perfectly. Using vh or % causes overflow when resizing the browser, while fixing it at the bottom results in overflowing the .top div. Since the .top div has transparent elements, hiding the .bottom div beneath it is not an option.

It seems like calculating the distance between the .top div and the bottom margin and setting it as the height for the .bottom div might be the key. However, despite searching for solutions extensively, I haven't found a suitable answer yet.

Just to clarify, this question is unique and not a duplicate of similar queries. Compatibility is also a priority, ruling out options like Flexbox and JavaScript.

Answer №1

Here is a solution that could meet your requirements. It doesn't take into account the margin, but I believe that won't be a problem in this case.

.bottom { height: calc(100% - 220px); }

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

Trouble aligning Material UI data-table columns (table head) to center in React

I have a data table where I declare rows and columns as simple variables, making it difficult to style them using 'style={{textAlign: center}}'. I tried adding a CSS file, but it did not work with the Material UI table. I am unsure of how to proc ...

What is the best method for sending data from an HTML page to a Django view in order to utilize it

I'm encountering an issue with Django urls. I need to pass the value entered in the Name input field after clicking the submit button. Let's assume I have the following HTML form- <form method='POST' action="{% url 'submittedf ...

Setting image height for consistent display across all browsers

I have searched both this forum and Google before posting this question, but unfortunately, the methods provided do not seem to work for me. Perhaps I am doing something incorrectly. The page I am working on looks like this: enter image description here ...

Eliminate the underline effect when hovering over an element by using the

I am currently using a unique font to create icons for my navigation elements in the website example below: The issue I am facing is that when a link is hovered over, both the link and the icon underneath display an underline. I would like to find a solu ...

HTML containers continue to show gaps even with no margin or padding applied

I have a basic setup here with a single line of red text on a colored background. Despite setting margin and padding to zero and not having any child elements causing spacing issues, I still see a gap around my container. Here's my CSS: { width: ...

IE8 - Unable to use rgba()

I'm currently facing an issue with RGBA() manipulation in jQuery while using IE 8. Here's the code I have so far: $('.set').click(function (e) { var hiddenSection = $('div.hidden'); hiddenSection.fadeIn() . ...

Remove a data entry from the MySQL database by selecting the corresponding row in the table and utilizing the DELETE function

Is there a way to remove a record from my MySQL database by clicking on a row in a table that is generated using ejs? Below is the code I am currently using to generate the table rows. <% res.forEach(function(item){ %> <tr> ...

I am having an issue with a mobile JQuery collapsible div that is not properly displaying the internal div within the item

Mobile JQuery jquery.mobile-1.0rc2.min.js HTML 5 Asp.net 4.0 I am having trouble with a gridview item-template where I have implemented the collapsible div from JQuery Mobile. The label text within the h3 element can be quite long, and I want to clip it i ...

Get rid of all the formatting on an HTML button or submit

Is there a method to entirely eliminate the styling of a button in Internet Explorer? I am utilizing a CSS sprite for my button and everything appears fine. However, when I click on the button, it shifts slightly upwards which distorts its appearance. Are ...

What could be causing the list-group and list-group-item classes to not take effect in this situation

Currently diving into Bootstrap 5, I decided to play around with lists. Here is a snippet of the code I'm working with: <ul class="list-group"> <li class="list-group-item">Cras justo odio</li> <li class="l ...

My online platform appears fine across all browsers except for Firefox

It seems that different browsers are displaying my website differently. Chrome, Safari, and Opera show it without any issues, but Firefox removes the top section, including the menu, and replaces it with white space in the center. I'm not sure what&ap ...

"Transforming your menu into a fully responsive Bootstrap menu: a step-by

Struggling to implement a responsive and animated Bootstrap 5 menu in this Codepen example. Tinkered with a few things, but it always seems to break one way or another. Check out the example here Looking to swap out the current menu with a Bootstrap menu ...

Update a Mysql variable by altering its value during the subtraction of two other variables

I'm struggling with how to phrase this. I have a database that contains customer invoice data including the "Date" of the procedure, the "Due_Date" (payment due date), and "Aging" (number of days overdue). What I want to do is calculate the aging by ...

Arranging Bootstrap 4 rows and columns in a vertical stack rather than horizontally

For some reason, I can't seem to get my .temp and .city divs to display side by side - they just keep stacking vertically. I've messed around with the column sizes but nothing seems to work. Any suggestions? <div class="col-lg" id ...

How can we use withStyles to customize the styling of a selected ListItem in ReactJS and Material UI?

I am seeking assistance in changing the style of a specific ListItem, similar to what is demonstrated in this Codesandbox. In the Codesandbox example, a global CSS stylesheet is utilized, but I prefer to implement the changes using the withStyle techniqu ...

Understanding the purpose of the notched property in Material-UI

I am currently integrating Material-UI into a project and exploring their API. One thing that I find confusing is the notched property within the OutlineInput Component. <FormControl variant='outlined'> <OutlinedInput notched={false} ...

ASP.NET Core 2.1 struggling to implement Shared Layout view across all views

I am facing an issue where the layout view is not consistent across all pages on my website. While the home page and main pages share the same layout, other pages like the login page lack styling and images. Additionally, features like CRUD operations also ...

What is the best way to create a text input that is both secure and non-editable?

While I am aware of the <input type="text" readonly /> possibility, it is not entirely secure. For example, if there is an input field that must remain uneditable by users, making it "readonly" can still be bypassed by inspecting the code and remov ...

Tips on utilizing the PHP json_decode() function with an array of JSON objects

I am having some trouble with an array of PHP objects that are json_encoded. I want to display these objects in a table in HTML, using the object's attributes as rows in the table. However, when I decode the JSON objects one by one in a for loop and d ...

Abnormal scrolling issues observed on handheld devices like mobile phones and tablets

I recently added a parallax effect to the hero section of my website, and while it works perfectly on desktop, I encountered some scrolling issues when viewing it on mobile or tablet devices. Sometimes the scrolling behaves as intended, and other times it ...