Shopify themes, liquid, logos, and UX
Hello!
I would like to make the element below sticky as I scroll down the page. It looks like the element on the left (the selection of coffees) is sticky, but I would like the picture to be sticky instead.
The pages I would like to edit are the following:
https://coffeeinboxes.com/products/coffee-box-of-4
https://coffeeinboxes.com/products/coffee-box-of-6
https://coffeeinboxes.com/products/coffee-box-of-9
Any help with this is greatly appreciated!
Thanks!
Solved! Go to the solution
This is an accepted solution.
- Here is the solution for you @SantosBaez
- Please follow these steps:
1. Go to Online Store --> Theme --> Edit code.
2. Open your theme.liquid file
3. In theme.liquid, paste the below code before </head> and press 'Save' to save it
<style>
.grid__item.product__media-wrapper.small-hide {
position: sticky !important;
top: 0 !important;
height: fit-content !important;
}
</style>
- Here is the result you will achieve:
- Please press 'Like' and mark it as 'Solution' if you find it helpful. Thank you.
If our suggestions are useful, please let us know by giving it a like or marking it as a solution.
Salepify: Efficiently increase sales conversion with sale-driven features like auto add to cart, free gifts (free plan available)
Salemate: Boost your AVO with 2-layer offer, countdown upsell in your post purchase page
This is an accepted solution.
- Here is the solution for you @SantosBaez
- Please follow these steps:
1. Go to Online Store --> Theme --> Edit code.
2. Open your theme.liquid file
3. In theme.liquid, paste the below code before </head> and press 'Save' to save it
<style>
.grid__item.product__media-wrapper.small-hide {
position: sticky !important;
top: 0 !important;
height: fit-content !important;
}
</style>
- Here is the result you will achieve:
- Please press 'Like' and mark it as 'Solution' if you find it helpful. Thank you.
If our suggestions are useful, please let us know by giving it a like or marking it as a solution.
Salepify: Efficiently increase sales conversion with sale-driven features like auto add to cart, free gifts (free plan available)
Salemate: Boost your AVO with 2-layer offer, countdown upsell in your post purchase page
Hello!
Thanks for replying! This code worked, however, could we add padding/margin to the top so there's some space between the image and the top of the browser?
Thanks!
<style>
.grid__item.product__media-wrapper.small-hide {
position: sticky !important;
top: 20px !important;
height: fit-content !important;
}
</style>
If our suggestions are useful, please let us know by giving it a like or marking it as a solution.
Salepify: Efficiently increase sales conversion with sale-driven features like auto add to cart, free gifts (free plan available)
Salemate: Boost your AVO with 2-layer offer, countdown upsell in your post purchase page
Can you try this code @SantosBaez
If our suggestions are useful, please let us know by giving it a like or marking it as a solution.
Salepify: Efficiently increase sales conversion with sale-driven features like auto add to cart, free gifts (free plan available)
Salemate: Boost your AVO with 2-layer offer, countdown upsell in your post purchase page
You can increase 20px to a larger number if you want more distance and vice versa @SantosBaez
If our suggestions are useful, please let us know by giving it a like or marking it as a solution.
Salepify: Efficiently increase sales conversion with sale-driven features like auto add to cart, free gifts (free plan available)
Salemate: Boost your AVO with 2-layer offer, countdown upsell in your post purchase page
Awesome! This worked!
Thank you!!
Glad to help you. Have a good day @SantosBaez .
If our suggestions are useful, please let us know by giving it a like or marking it as a solution.
Salepify: Efficiently increase sales conversion with sale-driven features like auto add to cart, free gifts (free plan available)
Salemate: Boost your AVO with 2-layer offer, countdown upsell in your post purchase page
Hello there!
I'm happy to help you make the media gallery section sticky on your product page. I've prepared some CSS and JavaScript code that you can add to your theme to achieve this effect. Here it is:
Add this to base.css in your theme:
.product__media-wrapper {
position: sticky;
top: 20px;
z-index: 1000;
height: fit-content;
}
@media screen and (max-width: 749px) {
.product__media-wrapper {
position: static;
}
}
Here's the JS code, please add this to your theme.liquid or theme script file.
<script>
let mediaWrapper = document.querySelector('.product__media-wrapper');
let productInfo = document.querySelector('.product__info-wrapper');
let header = document.querySelector('header');
function updateSticky() {
if (window.innerWidth <= 749) {
mediaWrapper.style.position = 'static';
return;
}
let headerHeight = header ? header.offsetHeight : 0;
let productInfoHeight = productInfo.offsetHeight;
let mediaWrapperHeight = mediaWrapper.offsetHeight;
let windowHeight = window.innerHeight;
if (productInfoHeight > mediaWrapperHeight && windowHeight > mediaWrapperHeight + headerHeight + 40) {
mediaWrapper.style.position = 'sticky';
mediaWrapper.style.top = `${headerHeight + 20}px`;
} else {
mediaWrapper.style.position = 'static';
}
}
window.addEventListener('scroll', updateSticky);
window.addEventListener('resize', updateSticky);
updateSticky();
</script>
The JavaScript serves several important purposes that can't be achieved with CSS alone:
This code will make the media gallery sticky on desktop views while keeping it static on mobile devices. It also adjusts for your header height and ensures the sticky behavior only applies when it makes sense for your layout.
Let me know if you need any further assistance or have any questions about implementing this code. I'm here to help!
Thanks,
Shubham | Untechnickle
Helping for free: hello@untechnickle.com
Don't forget to say thanks, it'll make my day - just send me an email!
Get Revize for Free | Let your shoppers edit orders post-purchase | Get Zero Support Tickets | #1 Order Editing + Upsell App
Discover how to increase customer engagement on your store with articles from Shopify A...
By Jacqui Apr 23, 2025Hey Community 👋 Did you know that March 15th is National Everything You Think Is W...
By JasonH Apr 1, 2025Discover how to increase the efficiency of commerce operations with Shopify Academy's l...
By Jacqui Mar 26, 2025