On the width of fixed elements

  <div class="wrap">
    <div class="header"></div>
    <div class="main"></div>
  </div>
When

header is set to position:fixed , how do I make its width equal to the width of the parent element wrap ?

is there any pure css implementation?

= =
explanation of the answer adopted:

clipboard.png

Source: influence of transform on elements

transform downgrade fixed to absolute , so the width is adaptive, so
so fixed element width adaptation can only be handled with js ?

Apr.06,2022

parent element plus 3D transformation is fine, for example: transform: scale3d (1,1,1);


just tried one, left and right are set to 0, and then the width is the same as before


I tried it with width: calc (100%-224px). No, no, no.


fixed is relative to the window element in html, so if you cannot achieve a width equal to its parent element in pure CSS, I will give you two solutions:
1, setting width and its parent element value equal under fixed;
2, replacing fixed with absolute;


you can use

if you don't consider compatibility.
absolute
Menu