In IE11, the fixed position does not depend on the parent container

In Chrome and Firefox, when a transform is defined in the parent container, the child's position will inherit from the parent container. However, this behavior does not occur in IE.

So, how can I ensure that it works in IE11 so that the child's position is always relative to the parent container?

div.fixed {
  position: fixed;
  top: 100px;
  width: 300px;
  height: 100px;
  border: 3px solid #73AD21;
  background-color: red;
  transform: translate3d(0, 0px, 0);
}

div.fixed2 {
  position: fixed;
  top: 100px;
  width: 300px;
  height: 100px;
  border: 3px solid #73AD21;
  background-color: blue;
}
<div class="fixed">
  <div class='fixed2'></div>
</div>

Answer №1

What is the necessity of having a fixed element within another fixed element?

You could simply use position: absolute for the child instead. It might be worth checking if this solution works for you.

If you truly require both elements to be fixed, perhaps consider making them sibling elements.

Here is an updated code snippet:

div.fixed {
  position: fixed;
  top: 100px;
  width: 300px;
  height: 100px;
  border: 3px solid #73AD21;
  background-color: red;
  transform: translate3d(0, 0px, 0);
}

div.fixed2 {
  position: absolute;
  top: 100px;
  width: 300px;
  height: 100px;
  border: 3px solid #73AD21;
  background-color: blue;
}
<div class="fixed">
  <div class='fixed2'></div>
</div>

Answer №2

The problem arises from having a transform property set on the first element, which creates a new stacking context for the positioning of fixed elements. Removing this property will resolve the issue. If you still need to optimize performance by offloading tasks onto the GPU, consider nesting the specific element that requires it. Refer to the specification for more details.

Answer №3

For a deeper understanding of the position property, I recommend checking out this resource: https://www.w3schools.com/cssref/pr_class_position.asp.

In terms of good programming practices, it's advisable to steer clear of using generic words like fixed as class names to prevent conflicts with reserved keywords. Additionally, opting for more descriptive class names is recommended.

If you want to position the inner div relative to the outer div, consider implementing code similar to the following...

div.outerDiv
{
    background-color : red;
    border           : 3px solid #73AD21;
    height           : 100px;
    position         : fixed;
    top              : 100px;
    transform        : translate3d( 0, 0px, 0);
    width            : 300px;
}

div.innerDiv
{
    background-color : blue;
    border           : 3px solid #73AD21;
    height           : 100px;
    left             : 20px;
    position         : absolute;
    top              : 10px;
    width            : 300px;
}
<div class = "outerDiv">
    <div class = "innerDiv">
    </div>
</div>

Answer №4

When an element is fixed, it means it is positioned relative to the window, rather than its parent element.

To test this, simply include the line "left: 10px" and observe that the element is not aligned with the parent. This behavior will be consistent across all browsers.

Check out this JSFiddle example for demonstration.

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

Integrate a scrollbar seamlessly while maintaining the website's responsiveness

I encountered an issue where I couldn't add a scrollbar while maintaining a responsive page layout. In order to include a scrollbar in my datatables, I found the code snippet: "scrollY": "200px" However, this code sets the table size to 200 pixels r ...

Modifying the href attribute of a hyperlink with jQuery

Is it possible to modify the href attribute of a hyperlink using jQuery? ...

Transitioning between different hues using specific fraction values

On my website, there is a variable called 'x' which represents a percentage. I am looking for a way to assign colors based on this percentage - with 0% being red and 100% being blue. For example, if 'x' is 50%, the color should be a mix ...

After refreshing the iframe, the OnStateChange function fails to work properly

My iframe is set up to play videos within a specific time range but I'm encountering an issue. When the end time is reached (case 0), I want to reload a slightly different URL (with autoplay=0). The problem arises when OnStateChange doesn't reco ...

JavaScript: Implementing lodash/fp flow to retrieve a collection of objects

Currently, I am in the process of transitioning a series of functions from _.chain to _fp.flow. However, I am encountering some challenges when dealing with currying complex objects within the flow. My goal is to: Transform an array of objects using grou ...

Creating multiple instances in ReactJS: A step-by-step guide

Having trouble figuring out how to add multiple jockeys to a racing program using this jockey program. It was working fine with just one jockey, but as soon as I try to add a second or multiple jockeys, issues arise. Where is the logic going wrong? App.js ...

Integrating tilt and zoom functionality on a web page based on mouse movements

While browsing through some messages on chat, I came across something interesting: I noticed that as I moved my mouse left or right, the content would tilt in that direction, and when moving up and down, the content would zoom in or out. It was a really c ...

Navigating directly to a page in ReactJS and Redux without needing to login if a token is found in the local storage

Currently in the main component, it is set to automatically redirect to the Login page. However, I want to implement a check to see if a token is already stored in the local storage. If a token exists, I want the application to skip the Login page and dire ...

Pressing the button is causing the Kendo Angular ToolBar Overflow button to refresh the page

Currently, I am using the Kendo Angular toolbar. As users resize the screen, an overflow button becomes visible. However, upon clicking this button, the page refreshes and appears to be performing a post back. Below is the code snippet: <kendo-toolbar ...

Toggle draggable grid in jQuery

Imagine I have a grid set up using the following code: $( "#dragIt" ).draggable({ grid: [ 15, 15 ] }); Now, there is a checkbox located below the div. Is there a way for me to switch the grid on and off by toggling the checkbox? I've searched the of ...

Using an onclick function to increment and decrement values

Can anyone help me figure out how to reverse a function onclick? Here is the function: var theTotal = 0; $('button').click(function(){ theTotal = Number(theTotal) + Number($(this).val()); $('.total').text(theTotal); }); ...

The JQuery File-Upload plugin remains inactive even after a file has been chosen

I am currently working on integrating the JQuery File-Upload plugin (). The issue I'm facing is that it doesn't respond when a file is selected. Here are some potential problems to consider: No errors appear in the Chrome console. Selecting a ...

Tips for keeping a div stationary when an adjacent div expands

I am facing an issue with 3 blocks in a row - a large block, a smaller block that can expand, and a third block placed under the first block. When the smaller block expands, the top of the third block moves to match the bottom of the expanding div. However ...

Incorporating HTML variables into a Django template without the need for escaping

I have encoded text in HTML format that looks like this: RT <a href="http://twitter.com/freuter">@freuter</a>... I would like to display this as formatted HTML, but I am unsure if there is a filter available to convert the encoded text back t ...

Tips for iterating through a JSON object in JavaScript and building a table from it

My JSON data is structured like this: diferencias = { "1": { "1": 543.0, "0": 542.0 }, "2": { "0 1": 0.3333333333333333 } } I am trying to create a table with the outer keys as columns. This is the code I have written ...

What are some methods to conceal an email address using Javascript?

let user = 'alex'; let domain = 'gmail.com'; let send = 'msg'; document.getElementById("email").href = "ma" + send + "ilto:" + user + "@" + domain; <a id="email"> <img src="imgs/pic.jpg"> </a> I have been w ...

Selecting an option from the drop-down list will change a text box to read

My current challenge involves making certain text boxes read-only based on the injury selected from a drop-down list. For example, if "thigh," "arm," "head," "heart," or "fingers" are chosen, specific text boxes will be restricted for input. For instance, ...

Join and authenticate

Currently, I am facing a rather peculiar issue. I have created a simple login form that seems to be functional halfway. Users can input their name and other details, but upon clicking the Submit button, I encounter an error stating "Undefined index: nameX" ...

What is the best way to create a clickable color feature that triggers a function to change the fill of an SVG object when clicked by the user?

I am attempting to create a user-friendly color selection system where users can click on colors that will then be applied to fill an svg object, similar to a digital coloring book for children. I am struggling to figure out how to instruct JavaScript to s ...

How to create a donut chart in Highcharts without an inner pie section?

I've been scouring the internet in search of a solution to create a basic donut chart using the Highcharts library. Most examples I come across show donut charts with both an inner pie and outer donut (see here). Is there a way to remove the inner pi ...