Skip to content

Instantly share code, notes, and snippets.

@doguscancalli
Created September 17, 2023 13:06
Show Gist options
  • Save doguscancalli/d999cbb7b4d036dcf3c5b8224e4ef7c2 to your computer and use it in GitHub Desktop.
Save doguscancalli/d999cbb7b4d036dcf3c5b8224e4ef7c2 to your computer and use it in GitHub Desktop.
How to Position a Fixed Element Relative to Its Parent with CSS

Issue: Difficulty in Positioning a Fixed Element Relative to Its Parent

Problem Description

When you need to position a fixed element relative to its parent element, it can be challenging to achieve the desired layout.

Solution

To position a fixed element relative to its parent, you can use the following CSS:

.parent {
  position: relative;
  transform: scale(1);
  
  /* Display purposes only */
  width: 1000px;
  height: 1000px;
  background: red;
}

.child {
  position: fixed;
  inset: 0;
  
  /* Display purposes only */
  background: blue;
}

Credits

Special thanks to the Stack Overflow user who provided this solution: Answer Link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment