I made some divs that hide most of the their content in a collapsible accordion like structure. So when I press "show more" in seperate div the content container with all the content expands to display it all and at the bottom I have the button that allow me to collapse it again. Like the the Shopify appstore here has. The issues is that when there is a lot of content if pushes the button to collaspe it way down. I would be better if I could leave the "Show less" at the bottom of the window until I’ve scrolled past the height of the content div. I thought CSS Position: sticky; Bottom: 10px;
would solve this, but no luck.
<div id="overview" class="preview-teaser " style="max-height: 140px; transition: max-height 1s ease-out 0s; bottom: 0px; padding-bottom: 15px; overflow: hidden;"><h3><span>Overview</span></h3>
<div class="field field--name-field-description field--type-text-long field--label-hidden">
<div class="field-items">
<div class="field-item even">
</div>
</div>
</div>
<div class="show-less" style="position: -webkit-sticky; max-height: 140px; bottom: 0px;"><span class="teaser-btn">show more >></span></div></div>
2
Answers
Add a max-height to the content. Add an
::after
with alinear-gradient
and some js for the hide/show functionality.Make the outer div as
position: relative
.Then you can position the
div.show-less
asabsolute
. The position of the div now depends on the outer div.Then instead of position from the bottom, you can position from top. use css function
calc
to get the right position: Set the height for the div equal to 50px. and set thetop: calc(100vh - 50px)
.vh
here is the height of the view the page is displaying