Jump to content

Replace custom horizontal line image with a mobile version automatically?

Recommended Posts

Posted (edited)

Is there a way to use jquery or something to swap out a specific image every time it is used?

I have an image of a handdrawn line (being used in place of a horizontal rule), and it's too thin on mobile since it shrinks down to fit the width of the screen. So, I made a shorter version of the line to be used on mobile and I'm using a media query to hide the mobile version on larger displays and hide the desktop version on mobile.

This works for me, but will be super confusing to my client down the road if they want to insert a line on another page, etc. 

Any suggestions on the easiest way to do this? 

site password: pottery

Here's an example of the desktop version: 

 

image.thumb.png.3fdd2581bfd782c184c470802d039f9a.png

 

 

 

And the mobile version....

 

image.thumb.png.9d05bb325bdf1a63d6fe67891ba49758.png

Edited by ovationcreative
  • Replies 7
  • Views 1.1k
  • Created
  • Last Reply

Top Posters In This Topic

Posted

To show different image on desktop - mobile easier for your clients, you can use this approach

  • add 2 images and these word to ALT: desktop mobile

image.thumb.png.804c78737bb63f882d107f6f3366e881.png

image.thumb.png.92f44ee2968e0dd03e0e740a42d51dfe.png

  • Next, use this code to Website Tools > Custom CSS
/* Hide Image with ALT: mobile on Desktop */
@media screen and (min-width:768px) {
  div.image-block:has([alt*="mobile"]) {
      display: none !important;
  }
}
/* Hide Image with ALT: desktop on Mobile */
@media screen and (max-width:767px) {
	div.image-block:has([alt*="desktop"]) {
	display: none !important;
}
}

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Posted
On 9/4/2024 at 3:47 AM, ovationcreative said:

Great idea. Thanks!

This works, but it still shows both lines while in the editor. Is there anything I can add to the code to fix that? I feel like that's still a little confusing from the client side.

Example: https://j-berens-pottery-demo.squarespace.com/pottery-care

(password: pottery) 

Can you take a screenshot in edit mode?

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

  • 2 months later...
Posted
On 9/7/2024 at 9:56 AM, ovationcreative said:

Here you go. Thanks for looking at it!

 

 

screenshot-edit.jpg

You can target Block ID instead

/* Hide Image with ALT: mobile on Desktop */
@media screen and (min-width:768px) {
  enter-mobile-image-block-id-here {
      display: none !important;
  }
}
/* Hide Image with ALT: desktop on Mobile */
@media screen and (max-width:767px) {
	enter-desktop-image-block-id-here  {
	display: none !important;
}
}

Follow this to find ID

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

Contact Customer Care - Learn CSS - Buy me a coffee (thank you!)

Create an account or sign in to comment

You need to be a member in order to leave a comment

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.