Jump to content

[Share] Add a dropdown next to header button

Recommended Posts

Posted

If it doesn't work, you can send link to your site + exact code you added, I will check again.

To add a dropdown next to header button, you can follow these.

#1. You can add a dropdown to Main Navigation

image.png.b242642e85c6f7b3442d8fea9f188b69.png

You can place any texts in Name, but in URL, use this URL: /button-dropdown

image.png.331df00d7fd8f9d6d9986a826eac5b9f.png

#2. Use this code to Code Injection > Footer

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
    $('div.header-display-desktop div.header-nav-item:has(a[href="/button-dropdown"])').insertAfter('.header-display-desktop a.btn');
});
</script>
<style>
.header-actions--right .header-actions-action {
    display: flex;
    justify-content: center;
    align-items: center;
}
.header-actions--right .header-actions-action a.header-nav-folder-title:after {
    content: "\e009";
    font-family: 'squarespace-ui-font';
    position: relative;
    top: 2px;
}
.header-actions--right .header-actions-action .header-nav-folder-content {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    opacity: 0;
}
.header-actions--right .header-actions-action div.header-nav-item {
    position: relative;
    right: -20px;
}
.header-actions--right .header-actions-action div.header-nav-item:hover .header-nav-folder-content {
    opacity: 1;
}
</style>

image.png.ddf26ad417b36d01b3e51e00116a7a7a.png

#3. Result

image.png.4792c860b1ee4b65da0e654c3f601896.png

#4.1. If you want to move Dropdown before Header Button, just change this to

insertBefore

image.png.5622dfdd3ad351cee4d86d489b99a06a.png

#4.2. If you want to change Dropdown Title to button, use this code before </style>

div.header-nav-item a[href="/button-dropdown"] {
    background-color: #000;
    color: #fff;
    padding: 15px 40px;
    border-radius: 50px;
}

image.png.8a0e2547b8ca0afe17ca83596d471ee5.png

Result

image.png.be2b324608f3ef70914fe5553aee97f8.png

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

  • Replies 2
  • Views 109
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Posted Images

Posted

Hi! @tuanphan! I love your shares and your replies have helped me so much with my sites.

I'm designing a site for an author and looking for a way to create a dropdown "buy now" button in my intro section, that will link to the different places someone can buy their book. Similar to the "Buy the book" button on this site.

Would this code also work for this? Can you share how to update the code to target a button in a specific section?

Posted
25 minutes ago, helloluci said:

Hi! @tuanphan! I love your shares and your replies have helped me so much with my sites.

I'm designing a site for an author and looking for a way to create a dropdown "buy now" button in my intro section, that will link to the different places someone can buy their book. Similar to the "Buy the book" button on this site.

Would this code also work for this? Can you share how to update the code to target a button in a specific section?

Follow this

 

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.