When the page is too long, the sidebar will disappear with scrolling and the page will not look as neat and beautiful. So this article will introduce how to use sticky widgets to avoid this problem.
Create a New Sticky Widget#
First of all, create a partial under the layouts/parials
folder, let’s take layouts/partials/custom/sticky-info.html
as example.
<div class="row card component position-sticky" style="top: 84px;">
<div class="text-center py-3 px-1">
MY STICKY WIDGET
</div>
</div>
The filename
custom/sticky-info
can be changed at will, but we recommend using some more specific names to avoid overriding the theme’s partials later. Such ascustom
,mywidgets
.
Then use the layouts/partials/hooks/sidebar-end.html
hook to include the sticky partial.
{{- partial "custom/sticky-info" . }}
The sticky widget should be the last widget of the sidebar, otherwise, strange problems can occur.
Make an Existing Widget Sticky#
Each widget will have a unique class name, so that we can apply CSS on a desired widget, here we take the profile widget as an example.
.sidebar {
.profile {
position: sticky !important;
top: 84px;
order: 5;
}
}
We need to specify the order
property to make the profile widget become the last widget of sidebar.
Comments