I'm trying to (mis)use display:sticky
in order to replace the (mis)use of floats in page layout.
I found there's this nice behaviour that aligns a sticky element to the edge of the opposite side no matter how much further you try to push it and I'm exploring how it may be used.
For example, if there's a sibling of unknown height (or even more siblings, floats can only deal with just one), it can be vertically aligned nicely, with something like {position:sticky;bottom:9999px;}
.
It works well, but with one side effect: the pushed element still takes its original space at the bottom, adding its own height to the height of the wrapper and thus pushing everything else lower.
.wrapper {
border:1px dashed black;
width:500px;
}
.main {
background:#eee;
width:300px;
margin-left:200px;
}
.aside {
background:#aaa;
width:200px;
position:sticky;
bottom:9999px;
}
<div class="wrapper">
<div class="main">
there is some stuff of unknown height.<br/>.<br/>.<br/>.<br/>.<br/>.<br/>.<br/>.<br/>.<br/>.<br/>.<br/>.<br/>.<br/>.<br/>
</div>
<div class="main">
and there some more.<br/>.<br/>.<br/>.<br/>
</div>
<div class="aside">
this goes nicely to the top without float or absolute positioning // but still occupies it's spot at the bottom ↓↓↓
</div>
</div>
I want to get rid of that space, but:
- with pure css / no extra markup
- no position:absolute / would be even worse than floats
- no display:grid /
it's overkilluntil masonry is supported, it would need extra js in the overall context.
I tried with a negative bottom margin, but it doesn't work, no matter how high I set it. Neither does hiding the overflow of either the element or the wrapper. Also, couldn't find anything in the dom inspector hinting to what generates it, but maybe I didn't know where to look.
Wouldn' be surprised that it's either not possible at all or it's just stupid simple.