Jump to content

Custom CSS in Header Won't Work on Mobile

Go to solution Solved by tuanphan,

Recommended Posts

Hello, 

I've implemented custom CSS for a logo in my header, which you can see in the attached photo as a white rectangle. This logo also functions as a smooth scrolling anchor link on desktop browsers. However, I'm encountering an issue on mobile devices where clicking the logo refreshes the page instead of smoothly scrolling to the linked section.

Could anyone help me modify the code so that it works correctly on mobile devices as well?

Thank you.

squarespace header problem.jpg

Link to comment
  • Replies 9
  • Views 1.3k
  • Created
  • Last Reply

Top Posters In This Topic

Posted (edited)

Use this new code to Code Injection > Footer

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('header#header .header-title a').attr('href','#top');
});
</script>

 

Edited by tuanphan
update code

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!)

Link to comment

This worked, but now my anchor-linked navigation titles also bring me to the top. Please check my site to see what I mean. Is there a way to apply this code so it only affects the image/logo, and no the titles. I greatly appreciate the help.

Link to comment
On 5/10/2024 at 11:16 PM, tuanphan said:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('header#header .header-title a').attr('href','#top');
});
</script

Thanks for your reply. Unfortunately, I've tried this code and it doesn't seem to work. See image here of the code being added to my website footer. You can also check the site to see that my header titles are still incorrecly anchor linked due to this. Any idea on how to fix this? Maybe another code.

Thanks again for your help. I really appreciate it.

Screenshot 2024-05-21 at 3.52.46 PM.png

Link to comment

I also tried the code in the header. Is this code supposed to go in the header or footer? Or both? I think there are two scripts conflicting. 

The other menu links don't seem to work if we have this code. As mentioned before, I am looking to retain the original menu links that I had previously, while having this code allow for my mobile logo to be anchor linked.

Screenshot 2024-05-21 at 3.58.28 PM.png

Link to comment

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.