html - Position:fixed menu disappears when using bottom:0 -
testing on chrome: want menu stick bottom left. shows when not using bottom: 0
. if use top
works. causing issue?
.mobile-menu { display: block; position: fixed; left: 0; bottom: 0; margin: 0; padding: 30px; width: 80px; z-index: 999; background-color: red; }
<div class="wrapper"> <nav class="mobile-menu">testing menu</nav> <header class="header"> <div class="main-logo"> <object data="svg/main-logo.svg" type="image/svg+xml"> <img src="fallback.jpg" /> </object> </div> <nav class="main-nav"> <ul> <li><a href="">about</a> </li> <li><a href="">services</a> </li> <li><a href="">contact</a> </li> </ul> </nav> </header> </div>
make .wrapper
position: relative
, .mobile-menu
position: absolute
. in order illustrate problem better, added content under header. green menu = good
, red menu = bad
.
solution
- in demo have renamed red menu to:
.mobile-menuoriginal
- i have added identical
.mobile-menu
, changedbackground-color: green
,position: absolute
reasons
position: fixed
place element relative viewport,bottom:0
place element @ bottom of screen.position: relative
places element in relation it's original position, placing.wrapper
inposition: relative
no specific coordinates (i.e.top
,right
,left
, ,bottom
),.wrapper
stays is. reason why.wrapper
needs can out of normal flow.position: absolute
places element in relation it's parent, putting.mobile-menu
absolute
positioning, position within borders of.wrapper
because.wrapper
.mobile-menu
's parent , closest positioned element. mentioned closest positioned because there exceptions said positioned parents. please refer article before confuse you.
edit
@t.niese further explains:
[...]the reason why .wrapper needs can out of normal flow.[...] out of flow bit misleading, because element position relative has visual displacement object, still use same space in flow before , still influenced surrounding in contrast absolute move element out of flow.
.wrapper { position: relative; } .mobile-menu { display: block; position: absolute; left: 0; bottom: 0; margin: 0; padding: 30px; width: 80px; z-index: 999; background-color: green; } .mobile-menuoriginal { display: block; position: fixed; left: 0; bottom: 0; margin: 0; padding: 30px; width: 80px; z-index: 999; background-color: red; }
<!doctype html> <html> <head> </head> <body> <div class="wrapper"> <nav class="mobile-menu">testing menu</nav> <nav class="mobile-menuoriginal">testing menu</nav> <header class="header"> <div class="main-logo"> <object data="svg/main-logo.svg" type="image/svg+xml"> <img src="fallback.jpg" /> </object> </div> <nav class="main-nav"> <ul> <li><a href="">about</a> </li> <li><a href="">services</a> </li> <li><a href="">contact</a> </li> </ul> </nav> </header> </div> <section> <h1>title</h1> <h2>byline</h2> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> <p>content</p> </section> <footer> <h3>footer</h3> </footer> </body> </html>
Comments
Post a Comment