HTML Elements with Position Fixed will Inherit the Top and Left Property from Parents
HTML elements when set to position: fixed without defining the top or left CSS property will automatically inherit from their parents.
For Example
Click the button bellow to see a div inside a div to see the inner div inherit the parent div automatically.
<div style = "background-color: grey; height: 70%; left: 25%; position: fixed; top: 25%; width: 70%"> <div style = "background-color:black;position:fixed;width:50%;height:50%"></div> </div>
This can cause problem if you are makeing a sticking nav bar, menu, or modal. You need to adjuct the inner div's top or left CSS property to put where you want it to be.
Now try this new button
left:
right:
bottom:
<div style = "background-color: grey; height: 70%; left: 25%; position: fixed; top: 25%; width: 70%">
<div style = "background-color:black;position:fixed;width:100%;height:100%;left:0"></div>
</div>
We need to remember to define a top, left, right, or bottom CSS property with a position fixed element or it will show up in a unpredicted place.
Comments
Post a Comment