I am trying to make sticky footer inside of a horizontally scrolling element. I want that sticky footer to be aligned to the bottom, have auto height based on it's content and be as wide as scroll parent (in this example 200px), so when I scroll to the right, footer is on the same place and it's content is horizontally centered (content should be some element, not only a simple text). I would appreciate help.
My current code:
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 0;
}
.example {
width: 200px;
overflow-x: auto;
}
.container {
position: relative;
display: flex;
width: 400px;
height: 100px;
background-color: moccasin;
}
.footer {
position: sticky;
bottom: 0;
background-color: palegreen;
justify-self: center;
}
<div class="example">
<div class="container">
<div class="footer">
Footer
</div>
</div>
</div>
Thanks a lot.
Hope this solves your issue: (Added Lorem Ipsum to show the scroll effect and footer being fixed)
* {
box-sizing: border-box;
outline: 1px solid red;
}
body {
margin: 0;
padding: 0;
}
.example {
width: 200px;
height: 300px;
overflow-x: auto;
}
.container {
position: relative;
display: flex;
flex-direction: column;
width: 400px;
height: 100%;
background-color: moccasin;
}
.footer {
position: sticky;
width: 200px;
height: 20px;
top: 100%;
background-color: palegreen;
text-align: center;
left: 0;
}
<div class="example">
<div class="container">
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has
survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing
software like Aldus PageMaker including versions of Lorem Ipsum
<div class="footer">
Footer
</div>
</div>
</div>