Shopify themes, liquid, logos, and UX
The sticky header is enabled in our theme settings, it is working fine for mobile.
But the PC/Desktop version is not working. (twigs.ae)
Solved! Go to the solution
This is an accepted solution.
Hello @nd23123
Please navigate to your Online Store, go to Themes, select Edit Code, and add the following code to the theme.liquid file, placing it before the </body> tag:
<script>
$(window).on("scroll", function() {
makeHeaderSticky();
});
var $header = $("#HeaderWrapper");
var sticky = $header.offset().top;
function makeHeaderSticky() {
if ($(window).scrollTop() > sticky) {
$header.addClass("sticky");
} else {
$header.removeClass("sticky");
}
}
</script>
<style>
.header-wrapper.sticky {
width: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 9999;
transition: all 0.3s ease-in-out;
}
</style>
Hello @nd23123
This seems to be working fine in my desktop.
Hey @nd23123
Follow these Steps:
1) Go to Online Store
2) Edit Code
3) Find theme.liquid file
4) Add the following code in the bottom of the file above </body> tag
<style>
@media screen and (min-width: 768px) {
header#SiteHeader {
position: fixed !important;
width: 100% !important;
margin-top: 28px !important;
}
.toolbar-section {
position: fixed !important;
width: 100% !important;
}
}
</style>
RESULT:
If I managed to help you then, don't forget to Like it and Mark it as Solution!
Best Regards,
Moeed
Hi Moeed, this worked, but on our products page there is a space above the header
Hey @nd23123
Try this code instead.
{% if template == 'index' %}
<style>
@media screen and (min-width: 768px) {
header#SiteHeader {
position: fixed !important;
width: 100% !important;
margin-top: 28px !important;
}
.toolbar-section {
position: fixed !important;
width: 100% !important;
}
}
</style>
{% endif %}
If I managed to help you then, don't forget to Like it and Mark it as Solution!
Best Regards,
Moeed
Hi @nd23123 , I hope you are doing well,
1. Go to Online Store -> Theme -> Edit code.
2. Open your theme.liquid file
3. Paste the below code before </body> on theme.liquid
<style>
@media screen and (min-width: 768px) {
header#SiteHeader {
position: fixed !important;
width: 100% !important;
margin-top: 28px !important;
}
.toolbar-section {
position: fixed !important;
width: 100% !important;
}
}
</style>
If my reply is helpful, kindly click like and mark it as an accepted solution.
Thanks!
HI @nd23123 ,
Steps to Follow:
Go to Online Store:
In your Shopify admin, navigate to Online Store in the left-hand menu.
Edit Code:
Click on the Themes section.
Under the current theme, click on Actions > Edit Code.
Find theme.liquid File:
In the left sidebar, under the Layouts folder, find and click on theme.liquid.
Add the Code Above the </body> Tag:
Scroll down to the bottom of the theme.liquid file.
Add the following code just above the closing </body> tag:
<style>
header#SiteHeader {
position: fixed !important;
width: 100% !important;
}
.toolbar-section {
position: fixed;
width: 100%;
z-index: 7;
}
</style>
I hope this helps! If it does, please like it and mark it as a solution!
If you need further assistance, feel free to reach out!
Regards,
Sweans
This is an accepted solution.
Hello @nd23123
Please navigate to your Online Store, go to Themes, select Edit Code, and add the following code to the theme.liquid file, placing it before the </body> tag:
<script>
$(window).on("scroll", function() {
makeHeaderSticky();
});
var $header = $("#HeaderWrapper");
var sticky = $header.offset().top;
function makeHeaderSticky() {
if ($(window).scrollTop() > sticky) {
$header.addClass("sticky");
} else {
$header.removeClass("sticky");
}
}
</script>
<style>
.header-wrapper.sticky {
width: 100%;
position: fixed;
top: 0;
left: 0;
z-index: 9999;
transition: all 0.3s ease-in-out;
}
</style>
thanks for this, it works well now.
By investing 30 minutes of your time, you can unlock the potential for increased sales,...
By Jacqui Sep 11, 2024We appreciate the diverse ways you participate in and engage with the Shopify Communi...
By JasonH Sep 9, 2024Thanks to everyone who participated in our AMA with 2H Media: Marketing Your Shopify St...
By Jacqui Sep 6, 2024