Are Stacked DIVs with Variable Height Top DIV Compatible with CSS?

I am currently experimenting with stacking two boxes on my mobile web application view using HTML/CSS. I prefer not to utilize JavaScript or hardcode values in this basic design.

Specifics:

  • The top box must have a dynamic height, with contents that are absolutely positioned and able to handle overflow (hidden if out of bounds).

  • The bottom box should have a fixed height.

View Image Here

I've been playing around and managed to create a solution found here. This design works well in Safari and Firefox. However, I am uncertain whether the CSS is entirely valid. Will it potentially break due to violating some obscure styling rule in the future? If so, how can I adjust the code to ensure validity?

I am not worried about browsers breaking the layout due to rendering issues, as those typically get resolved. My main concern is having correct and valid code from the beginning.

Below is the code snippet with CSS styling included in the fiddle:

<!-- body section containing padding -->
<div class="BodyContainer" >
    <!-- table definition -->
    <div class="table" style="padding: 0; margin: 0; width: 96vw">
        <!-- row -->
        <div style="display: table-row; padding: 0; margin: 0">
            <!-- cell -->
            <!-- dynamic height cell requiring overflow hidden -->
            <div class="cell" style="width: 100%">
                <!-- inner relative cell -->
                <div style="position:relative; height: 100%; padding: 0">
                    <!-- absolute hidden cell taking up entire space -->
                    <div style="position:absolute; top: 0; bottom:0; left: 0; right:0; padding: 0; background: yellow; overflow: hidden;">
                        This text will be displayed on top 
                        <!-- fixed bottom content -->           
                        <div style="position: absolute; bottom: 0">
                        	This text will appear at the bottom of the cell
                        </div>
                       <br>
                    </div>
                </div>
            </div>
        </div>
        <div style="display: table-row">
            <!-- fixed size bottom row -->
            <div class="cell" style="background-color: red; border-top: 2vw solid black;">
            	<!-- customizable page content -->
            	<div style="height: 20vw !important;">
                	foo
            	</div>
            </div>
        </div>
    </div>
</div>

Answer №1

This looks like a well-built CSS3 code to me. Based on my evaluation, there is no indication that support for this style will be discontinued in the future.

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

Borders in my CSS/HTML table design

Hey, I'm currently facing an issue with my class project. I've created a table with a series of images to form a background image. However, there are borders on the table that I need to adjust. Here is the current look: I am trying to have a sq ...

Python Flask login application failing to redirect to login page

Currently, I'm building a login application with Python Flask and MongoDB integration at the backend. While everything else seems to be running smoothly, there's an issue with redirecting to the login page upon login. # See below for my code @ap ...

Create a CSS border that resembles the one used in Google's signup form

lies a curious inquiry: what unique border style is in play here? It rests slightly raised against the backdrop, creating an intriguing visual effect. After combing through various sources online, the answer still eludes me. Perhaps turning to Google' ...

Customize your Jquery UI Calendar with Changing Background Images for Each Month!

How can I change the background of jQuery UI datepicker based on the selected month? I have created 12 classes, each representing a month, and the selected month already has the background. I tried using "onChangeMonthYear: function(year, month, inst) { ...

Preventing Canvas Image Disappearance with JavaScript's onload Event

My current issue involves adding an Image to my webpage. However, every time I hit the refresh button, the image disappears. After researching on Stack Overflow, it was suggested to include window.onload=yourDrawFunction() in the code. Despite following th ...

Using jQuery to iterate through an array and reverse its order

Is there a way to loop through an array and change the CSS background color chronologically rather than randomly? Additionally, is it possible to reverse through the same array when the back button is clicked? http://jsfiddle.net/qK2Dk/ $('#right&a ...

what distinguishes CSS properties for Id versus class selectors

Currently in the process of creating my inaugural website, which consists of just four pages. Each page follows the standard layout structure with a header, navigation bar, content division (div id="content"), and footer. As I delve into adding CSS proper ...

Is there a way to contain the text within a div and have the div expand downwards if the text is too large?

Is there a way to ensure that text stays inside a div even if it exceeds the width, with the div's height expanding to fit the entire text? UPDATE: Thank you all for your help so far. Should I use 'Inherit' or 'min-height'? A ba ...

Error message: "not properly formatted" encountered on Firefox browser, while Chrome browser reports the issue as "XMLHttpRequest.." error

Currently, I am delving into the world of three.js and have successfully converted an .obj file to a .js file for my object. I loaded this object using JSONLoader and was able to view it on Firefox browser. However, a JavaScript exception appeared in the c ...

Supervise the interaction of users on the Express application

Recently, I began using Express and encountered a situation where I have a <table> on the users page with a link in each row to delete the entry. Whenever a user clicks on one of these links, I need to delete that entry from the database. Since this ...

Designing a dynamic 1-3 column arrangement with Angular for animated content

Let's discuss the current setup: I am in the process of creating a webpage for an application that includes a navigation bar, a footer, and a 3-column body layout. Initially, only one column is visible. This primary column will contain interactive d ...

The Outer Div Can't Contain Google Maps

I am currently working on integrating a map widget into a dashboard I created using gridstack.js. The sample widget layout that I am aiming for can be seen in the link below: https://i.sstatic.net/ZQP6G.png My goal is to embed the map within the inner (w ...

tips for personalizing your jQuery image preview script

Currently, I have implemented a jQuery script that allows me to preview multiple images before uploading them. Although the functionality works well, I am facing difficulties customizing it to meet my specific requirements. <script> $(document).r ...

Is anyone else having trouble getting the date picker range to work with jQuery?

In my ASP.NET MVC (C#) project, I have the following code snippet: form.cshtml: <div class="form-group"> <label for="birthday" class="cols-sm-2 control-label text-dark">Birthday</label> <div class=& ...

Random Image Generator in Javascript with Links

I am attempting to load one image at a time along with its corresponding link. My goal is to display the image in a div with an ID of 'ads'. Here is the code I have so far, but I am not proficient enough in JavaScript to achieve my desired outcom ...

How to align items at the center in material-ui styling

I have a row of cards inside a container that I want to align in the center with equal spacing around them. I am using the material-ui UI library for the layout. Despite adding the justifyContent: center property, the cards are not evenly spaced. This is ...

Creating a running text (marquee) with CSS is a simple and efficient way to make

I encountered a significant challenge while delving into CSS animation. My goal is to create a "transform: translate" animation that displays text overflowing the content width as depicted in the image below. https://i.stack.imgur.com/sRF6C.png See it i ...

Facing an infinite loop issue with my ng-view and the index.html page in AngularJS

Hello everyone, I have a question regarding AngularJS ngview. I just started learning about Angular a week ago. In my code, the webpage is showing an infinite loop of the index itself instead of displaying the correct page. I've searched on Stack Ove ...

Creating an email in Gmail with a pre-filled HTML body

Currently, I am developing a Django web application and seeking a way to enable my app to send emails via Gmail. I have explored creating a hyperlink that opens the compose window in Gmail, as well as prepopulating fields such as "to," "cc," "bcc," and bod ...

What is the best way to duplicate this content from a picture using CSS?

Trying to replicate text in an image using HTML and CSS. Wondering if there's a better way than setting each line with its own font size. Here's the image I'm working on: https://i.sstatic.net/bMPhy.png Current issues with the approach: ...