Shopify themes, liquid, logos, and UX
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
on mobile everyting already under collapsible rows. how can i do on desktop as well? please help. my store link
Hi @SinghSells ,
This is Amelia from PageFly - a Landing Page Builder App
Here's a step-by-step guide to help you achieve this:
Access the Theme Editor:
Go to your Shopify admin panel.
Navigate to Online Store > Themes.
Click on Actions > Edit code next to your theme.
Locate the Product Template:
In the Sections folder, find the template file that renders the product page. This might be product-template.liquid or a similar file.
Add Collapsible Sections:
Modify the HTML structure to include collapsible sections. For example:
<div class="collapsible-section">
<button class="collapsible">Product Description</button>
<div class="content">
<p>{{ product.description }}</p>
</div>
</div>
<div class="collapsible-section">
<button class="collapsible">Product Specifications</button>
<div class="content">
<p>{{ product.metafields.custom.specifications }}</p>
</div>
</div>
<div class="collapsible-section">
<button class="collapsible">Shipping Information</button>
<div class="content">
<p>{{ product.metafields.custom.shipping_info }}</p>
</div>
</div>
Open the CSS File:
In the Assets folder, open the theme.css or base.css file.
Add the Following CSS Code:
.collapsible {
background-color: #f1f1f1;
color: #444;
cursor: pointer;
padding: 18px;
width: 100%;
border: none;
text-align: left;
outline: none;
font-size: 15px;
}
.active, .collapsible:hover {
background-color: #ccc;
}
.content {
padding: 0 18px;
display: none;
overflow: hidden;
background-color: #f9f9f9;
}
Create a New JavaScript File:
In the Assets folder, click Add a new asset and create a new JavaScript file (e.g., collapsible.js).
Add the Following JavaScript Code:
document.addEventListener('DOMContentLoaded', function() {
var coll = document.getElementsByClassName("collapsible");
for (var i = 0; i < coll.length; i++) {
coll[i].addEventListener("click", function() {
this.classList.toggle("active");
var content = this.nextElementSibling;
if (content.style.display === "block") {
content.style.display = "none";
} else {
content.style.display = "block";
}
});
}
});
Include the JavaScript File:
In the Layout folder, open theme.liquid.
Add the following line before the closing </body> tag:
<script src="{{ 'collapsible.js' | asset_url }}"></script>
I hope that my solution works for you.
Best regards,
Amelia | PageFly
Please let me know if it works by giving it a Like or marking it as a solution!
➜ Optimize your Shopify store with PageFly Page Builder (Free plan available)
➜ Weekly updated Shopify tutorials on YouTube
All features are available from Free plan. Live Chat Support is available 24/7.
HI Thanks for this, Just one more question before I implement this code. Mobile version will be the same right? Because on mobile everything is perfect I don't want to change any thing on the Mobile.