Hide a section on the product page on mobile only

Hide a section on the product page on mobile only

aestheticanvas
Excursionist
24 1 2

Hello there,

 

I have made some changes to have my title and star rating appear before the image on mobile only, it works well on desktop as everything stays the same however, on mobile the star ratings are showing twice and I would like to hide the one showing at the bottom as I would like to have the star rating just below the title on mobile without affecting the desktop view.

 

Here is a link to one of my product pages, you can see the star ratings are appearing twice on mobile, I would like to hide the bottom one.

 

Thank you in advance for your time and help.

 

Kind regards,

Replies 5 (5)

Guleria
Shopify Partner
4147 809 1164

Follow these steps:

1. Go to Online Store -> Theme -> Edit code

2. Open your base.css file and paste the following code at the bottom:

@media only screen and (max-width: 767px) {
.desktop-rating-stars { 
    display: none !important;
}
}
- Custom themes, UI/UX design, ongoing maintenance & support.
- Drop an email   if you are looking for quick fix or any customization
- Email: guleriathakur43@gmail.com Skype: live:navrocks1
- Try GEMPAGES a great page builder
aestheticanvas
Excursionist
24 1 2

Hello, Thank you for your prompt answers.

 

Unfortunately, I have tried these three different codes and it still doesn't work, I am not sure why.

 

For more context, please find below screenshots of my product.liquid codes the first screenshot shows the liquid code that renders the stars above the image on mobile. And the second screenshot shows the code that should only render the stars on desktop.

 

Screenshot 2024-07-17 110552.png

Screenshot 2024-07-17 110618.png

 

Additionally, here is a screenshot of my CSS codes added to base.css:

 

Screenshot 2024-07-17 110652.png

 

Thank you again for everyone's precious time and help.

 

Kind regards

aestheticanvas
Excursionist
24 1 2

I've finally figured it out, I used some HTML directly in the product.liquid file as follow:

 

<style>
/* Hide the desktop-rating-stars element on screens narrower than 750px (mobile) */
@media screen and (max-width: 749px) {
.desktop-rating-stars {
display: none !important;
}
}

 

Just above this code:

 

<div class="desktop-rating-stars">
{% for block in section.blocks %}
{% case block.type %}
{% when 'rating_stars' %}
{% render 'rating-stars-block', block: block, margins: true, block_attributes: true %}
{% endcase %}
{% endfor %}
</div>

 

Which finally worked.

 

Thank you everyone for your help and contribution!

WalkYourStyle
Navigator
475 58 79

1. Go to 'Online Store' -> Themes

2. From your active theme click on the 3 dots (...) -> Edit Code

3. Inside the assets folder, locate the file 'base.css'

4. At the bottom of the file add

@media (max-width: 749px){
    .desktop-rating-stars{
        display: none;
    }
}

this code

BSS-TekLabs
Shopify Partner
2401 695 835

- Here is the solution for you @aestheticanvas 
- Please follow these steps:

step.png

- Then find the base.css file.
- Then add the following code at the end of the file and press 'Save' to save it.

@media (max-width: 749px){
    .desktop-rating-stars{
        display: none !important;
    }
}

- Here is the result you will achieve:

BSSTekLabs_0-1721148002164.png

 

 

- 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


BSS Commerce - Full-service eCommerce Agency | Use Shopify for 1$ in the first month now