Home > database >  Width of fixed positioned element using CSS
Width of fixed positioned element using CSS

Time:11-15

I have an element in my Web Page <div ></div>. Currently it is maintaining width of parent element. But if I apply position: fixed; on <div ></div> it's width increases.

How to keep previous width with position: fixed; ?

CodePudding user response:

set width to inherit so the child gets the width of the parent

width: inherit;

CodePudding user response:

The CSS specification requires that position:fixed be anchored to the viewport, not the containing positioned element.

Other way to do it is :- To set parent element position: relative; and child element position: absolute;

  • Related