html - Place an absolute element in bottom of a container with overflow: auto -
i have logo should positioned in bottom of fixed container. works ok position: absolute; if add overflow-y: auto; fixed container , add content doesn't fit viewport height, logo stick bottom of viewport, not bottom of fixed container, overlapping content.
<div class="foo"> <div class="content"></div> <div class="logo-in-the-bottom">logo</div> </div> .foo { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: gray; overflow-y: auto; } .content { height: 1000px; } .logo-in-the-bottom { position: absolute; bottom: 10px; left: 0; color: white }
how stick bottom of fixed container no matter content height?
try this:
depending on content:
.foo { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: gray; overflow-y: auto; } .content { min-height: 100%; height: 1000px; position: relative; } .logo-in-the-bottom { position: absolute; bottom: 10px; left: 0; color: white }
<div class="foo"> <div class="content"> <div class="logo-in-the-bottom">logo</div> </div> </div>
for future references:
sticky version:
.foo { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: gray; } .container { width: 100%; height: 100%; overflow-y: auto; } .content { height: 1000px; } .logo-in-the-bottom { position: absolute; bottom: 10px; left: 0; color: white }
<div class="foo"> <div class="container"> <div class="content"> </div> </div> <div class="logo-in-the-bottom">logo</div> </div>
you need add container overflow inside .foo
. why ? way .foo
fixed , absolute relative fixed position, not content because .container
1 overflowing.
on bottom:
.foo { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: gray; overflow-y: auto; } .content { height: 1000px; } .logo-in-the-bottom { position: relative; //no need absolute color: white }
<div class="foo"> <div class="content"> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <p>lorem ipsum </p> <div class="logo-in-the-bottom">logo</div> </div> </div>
Comments
Post a Comment