Ensure that the absolutely positioned divs are set to 50% of the height of their parent specifically for IE9

My goal is to have two divs fill the entire height of their container, which is a table-cell with variable height. Each div should take up 50% of its parent and be stacked on top of each other. To achieve this, I positioned the top one with top: 0; bottom: 50%; and the bottom one with bottom: 0; top: 50%. This method works well in most browsers except for IE9+.

On Chrome, Firefox, Safari, and surprisingly even IE8, my layout looks as expected. However, on IE9+, the absolutely positioned divs overlap for some reason.

This is what my layout markup looks like:

<div class="table">
    <div class="cell">
        Lorem ipsum dolor sit amet, consectetur adipiscing elit...
    </div>
    <div class="cell">
        <div class="top">TOP DIV</div>
        <div class="bottom">BOTTOM DIV</div>
    </div>
</div>

And here are the styles I'm using:

.table {
  display: table;
  background-color: #cbcbcb;
  border-spacing: 10px;
}

.cell {
  display: table-cell;
  vertical-align: middle;
  position: relative;
  width: 70%;

  &:first-of-type {
    width: 30%;
  }
}

.bottom,
.top {
  box-sizing: border-box;
  position: absolute;
  background-color: #fff;
  padding: 20px;
  width: 100%;
}

.bottom {
  bottom: 0;
  top: 50%;
  margin-top: 5px;
}

.top {
  top: 0;
  bottom: 50%;
  margin-bottom: 5px;
}

Feel free to experiment with the layout using this bin: http://jsbin.com/yifeqe/edit?html,css,output

Any suggestions or insights on why this issue is occurring?

Answer №1

It turns out that in Internet Explorer, the use of position:absolute is causing your divs to be blocked, resulting in only the bottom one being visible.

Internet Explorer doesn't handle position absolute well, so the solution is to instead use:

display:inline-block;

Here is an updated version on jsfiddle for reference.

IE Fiddle

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

Guide to Presenting HTML data stored in an SQL database on an ASP.NET webform

I need help figuring out how to dynamically display a blog page from my database. The content I'm pulling contains HTML tags, so right now it's showing the raw data with tags included. What I really want is for it to display like a proper page. ...

Create a div element that is set to be 30 pixels smaller than its containing div

I am trying to achieve a specific layout where I have a nested div structure. The parent div has a width set in percentage (80%) and I want the child div to be slightly narrower by 30px. Can anyone provide guidance on how I can accomplish this? Do I need ...

Tips for creating a web page layout that minimizes formatting issues when copying and pasting into Microsoft Word

As I work on developing a web application, I am aiming for users to have the ability to easily copy parts of the page and paste them into MS Word with minimal loss of HTML formatting. One scenario involves allowing users to copy just a table from the page ...

Why does col-sm-12 not fill the entire width on smartphones? Am I missing something?

SASS Breakpoints Definition: /* For the grid */ $grid-breakpoints: ( xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px, xxl: 1440px, xxxl: 1660px ); Structure of My Columns: <div id="footer_lower_menus" class="row"> ...

Using Angular, you can incorporate a dynamic href inside interpolation by using

Looking for a way to include a redirecting link within the response of string interpolation. I am incorporating the API response value into the interpolation binding. For instance, if my response is, "This site is not working. please contact google f ...

Issues encountered when using Vue Transition in conjunction with v-autocomplete

Attempting to conditionally display or hide a selection text field using Vue's Transition feature, but experiencing an issue where the text field appears and disappears without any transition effect. <template> <Transition v-if="is ...

How to position a label above a radio button using CSS

I have been attempting to position a label above a radio button using CSS. My desired outcome: This is the code I am currently using: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional. ...

Develop an AJAX script for processing multiple form inputs in PHP and HTML

I am working on a code that involves multiple form submissions, but the submit functionality is not working due to having multiple submits on one page. I have realized that I need an Ajax script to handle this, but I am new to it. Can someone provide me wi ...

JQuery Searchbar Failing to Hide Divs as Intended

I'm currently facing an issue with my <user-panel> elements, which are dynamically created using ng-repeat. Each of these elements contains child divs with the class user-panel-name. I've been attempting to use the text within these name di ...

The width property is not being passed down to the table

I'm experiencing difficulties with the scaling of my body content. When the page is initially opened, it scales to 100%. However, when I resize the screen to make it wider, the content gets bigger but when I try to make it smaller again, it remains a ...

Deactivating the button when the textarea is blank

When the textarea is empty, the "convert" and "clear value" buttons are inactive. They only become active when the textarea has a value. Manually clearing the value works as expected, but the issue arises when the "clear value" function empties the textar ...

Retain the input values even after the page is refreshed

I have developed a simple form validation page in ReactJS. The input fields are validated using regex patterns. One issue I encountered is that if I enter data in the input fields and refresh the page before completing the form, the input fields are clear ...

Issue with JQuery mobile: dynamically inserted popup fails to appear

Can you help me troubleshoot an issue with my function? It's supposed to take a text string and output the text surrounded by '¬¬¬' in a button with a pop-up menu attached. The button looks fine, but when clicked, the popup ul list doesn& ...

Can a font size be adjusted dynamically based on the width of its containing class?

I have encountered this issue before, but the previous solution did not work for me. I am now seeking a viable alternative. Currently, I am developing a website and have an event announcement block that needs to display the event date spanning the entire ...

Django: Crafting beautiful HTML without the need for CSS and selecting the perfect text

Greetings! This is my first attempt at building a website, so please bear with me as I navigate through this process. I have created a home page named home.html, which extends from base.html, and also a joke.html that similarly extends base.html. While the ...

Issue with Bootstrap navbar not collapsing to pills at the appropriate moment

Currently, my navbar contains links on the left side and social media buttons on the right. The issue arises when I resize the window - instead of collapsing into pills as desired, the social media buttons move under the links, creating a messy layout. Eve ...

You cannot use css() in conjunction with appendTo()

$('#item').click(function() { $.ajax({ url: 'server.php', type: 'POST', data : {temp : 'aValue'}, success: function(data) { $(data).css('color&apo ...

AngularJS has the ability to reverse progress bars

I have recently developed a small AngularJS application that includes a dynamic data table utilizing ng-repeat. The table reflects real-time changes in the data, with rows being updated, added, and removed through web socket communication. Each row in the ...

Why is the hashtag (#) mysteriously vanishing from the URL?

Imagine a scenario where you have a page with a URL like mypage.php#tab3, and there is a link that looks like this: When you click on the "Add" link, the URL becomes shorter to just mypage.php#. The code for the "Add" function is as follows: function ad ...

Bootstrap 4 menu toggle malfunctioning

After extensively searching for a solution to this issue on multiple threads in Stack Overflow, I am baffled as to why it is not working. The example below (taken from a thread on this topic) functions correctly in jsFiddler, but fails to work when served ...