Jump to content

[Share] Dropdown Menu CSS

Recommended Posts

Posted (edited)

Some CSS code to customize Dropdown Menu (7.1 version).

You need to insert code to Website Tools (under Not Linked) > Custom CSS

#1. Change Dropdown Background

div.header-nav-folder-content {
    background-color: #f1f !important;
}

image.png.2d54b67aea132f609d4afb35762f7870.png

#2. Change Dropdown Opacity

You can use rgba color to adjust opacity, suppose dropdown background color is #f1f, the code should be.

0.5 is opacity, it is 0 to 1

div.header-nav-folder-content {
    background-color: rgba(255,17,255,0.5) !important;
}

image.png.54604d97339224304f4dc971a8c83df7.png

#3. Dropdown Transparent

div.header-nav-folder-content {
    background-color: transparent !important;
}

image.png.90a13321d85d160dfdaef7e9d4b6652c.png

#4. Space between dropdown items

div.header-nav-folder-item {
    margin-top: 10px;
    margin-bottom: 20px;
}

#5. Add an arrow to Dropdown Title

a.header-nav-folder-title:after {
    content: "\e009";
    font-family: 'squarespace-ui-font';
    position: relative;
    top: 2px;
}

image.png.8909379f64fcfdef54e18a2523296cbd.png

#6. Dropdown round corners

div.header-nav-folder-content {
    border-radius: 30px;
}

image.png.5e31c52995ad77c8e5592469e09763df.png

#7. Align center dropdown

div.header-nav-folder-content {
    left: 50% !important;
    transform:translateX(-50%) !important;
}
.header-nav-folder-item {
    text-align: center;
}

#8. Align Left/Right Dropdown items

You can change right to left

div.header-nav-folder-content * {
    text-align: right !important;
}

#9. Change dropdown items background/color on hover

/* dropdown item hover background */
div.header-nav-folder-item:hover {
    background-color: #000 !important;
}
/* dropdown item hover text color */
div.header-nav-folder-item:hover * {
    color: white !important;
}

#10. Add an icon before dropdown item

First, you need to know this

image.thumb.png.ee887dbe873f66c8b1983e7edac57225.png

Suppose we need to add icons before Portfolio Custom & Gallery Grid Section items, we will use the CSS code

div.header-nav-item:nth-child(2) div.header-nav-folder-item span:before {
    content: "";
    background-size: cover;
    background-repeat: no-repeat;
    background-position: center;
    width: 30px;
    height: 30px;
    display: inline-block;
}
/* dropdown item 1 */
div.header-nav-item:nth-child(2) div.header-nav-folder-item:nth-child(1) span:before {
    background-image: url(https://cdn.pixabay.com/photo/2023/11/15/15/04/leaves-8390274_1280.jpg);
}
/* dropdown item 2 */
div.header-nav-item:nth-child(2) div.header-nav-folder-item:nth-child(2) span:before {
    background-image: url(https://cdn.pixabay.com/photo/2024/01/08/17/41/chokeberry-8496026_1280.jpg);
}

image.png.2e1210acd7e85af71db6483da1faaab7.png

#11. Align Horizontally Dropdown

div.header-nav-folder-content {
    display: flex;
    align-items: center;
    width: 100vw !important;
    right: unset !important;
    left: 50% !important;
    transform: translateX(-50%) !important;
    text-align: center !important;
}
div.header-nav-folder-item {
    margin-left: 10px;
    margin-right: 10px;
}

image.thumb.png.4e1ae7c8506b03787ecd7e61561777aa.png

 

#12. Dropdown 2 - 3 columns

div.header-nav-folder-content {
    column-count: 2;
}

#13. Dropdown Item color

span.header-nav-folder-item-content {
    color: #f1f !important;
}

If you have any problems, you can comment below with your site url.

Edited by tuanphan
update #13 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!)

  • 4 weeks later...
Posted
16 hours ago, buzzsites said:

The menu - About Us, Our services etc should all be aligned in the center of the box. 

Like this

 

 

 

Homepage Boxes.png

Use this new code

div.header-nav-folder-content {
    left: 50% !important;
    transform:translateX(-50%) !important;
}
div.header-nav-folder-content * {
    text-align: center !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!)

  • 5 months later...
  • 4 weeks later...
Posted

#14. Adding FontAwesome Icon in Dropdown

Suppose you have a Dropdown like this

image.png.989a9884427007ef8ac0602e62df29b0.png

First, you need to find Dropdown Item url. In my example, we will have

  • Item text block: /text-block3
  • Item image block: /image-block3
  • Item button block: /button-block 3

image.png.d001cd940d1c9156c0572e69cc993083.png

Next, add this code to Code Injection > Header (or if your plan doesn't support Code Injection, you can add it to Code Block in Site Footer)

 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" integrity="sha512-KfkfwYDsLkIlwQp6LFnl8zNdLGxu9YAA1QvwINks4PhcElQSvqcyVLLD9aMhXd13uQjoXtEKNosOWaZqXgel0g==" crossorigin="anonymous" referrerpolicy="no-referrer" />

image.thumb.png.d0a98a1b85c276b96e76519f15f1284a.png

Next, use this code to Custom CSS box

div.header-nav-folder-item [href="/text-block3"]:before {
    content: "\f129";
    font-family: "Font Awesome 6 Free";
    font-weight: bold;
    color: #000;
    font-size: 20px;
}
div.header-nav-folder-item [href="/image-block3"]:before {
    content: "\f03e";
    font-family: "Font Awesome 6 Free";
    font-weight: bold;
    color: #000;
    font-size: 20px;
}
div.header-nav-folder-item [href="/button-block3"]:before {
    content: "\f10a";
    font-family: "Font Awesome 6 Free";
    font-weight: bold;
    color: #000;
    font-size: 20px;
}

image.thumb.png.ebc08a58f8ee6e8c46af2b0f20fb321c.png

Result

image.thumb.png.f506b4d966e39f2fded095a2c47854c2.png

You can add these icon syntax

image.thumb.png.ee479b1a847d48820363111e3a9a321f.png

To find icon syntax, you can access FontAwesome website, choose an icon > Then see here

image.thumb.png.bb1d3140d742cdb70d15131d06d36969.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!)

Posted

#15. Dropdown Arrow (Down/Up arrow on hover)

Use this CSS Code

a.header-nav-folder-title:after {
    content: "\e009";
    font-family: 'squarespace-ui-font';
    position: relative;
    top: 2px;
}
a.header-nav-folder-title:hover:after {
    transform: rotate(180deg);
    display: inline-block;
}

Before hover

image.png.a3848f99345de13482dd3cf05af568f4.png

After hover

image.png.4698d6cd1c8f98d1b087d1b790f8455d.png

#16. Dropdown Active Color

Description: When users are on dropdown item page >> make Dropdown Title active (change color, add underline)

First, you need to find Dropdown Title URL

image.png.26e07b8e2fa2f20140817f50fe7ab7fb.png

In my example, we will have

image.thumb.png.ef278cef858816016080f544221bbf52.png

Next, You can edit all dropdown item pages > Add a Code Block > Use this code

<style>
  a.header-nav-folder-title[href="/incomplete"] {
    color: #f1f;
    text-decoration: underline;
}
a[data-folder-id][href="/incomplete"]>div>span:nth-child(2) {
    color: #f1f !important;
    text-decoration: underline !important;
}
</style>

image.png.5573e3ac2718dbe90b6d9d2d1865a113.png

Result

image.png.f32d89a59fbdcb5d24709f9ecb87208a.png

#17. Add scroll bar to Dropdown

If the dropdown has too many items, you can add a scroll bar.

You can follow #16 to find Dropdown Title URL, then use CSS code like this

a.header-nav-folder-title[href="/incomplete"] + div {
    max-height: 300px;
    overflow-y: scroll;
}

image.png.48378d5bc08e5ec0dd2372f6b6f1265f.png

Result

image.png.690a7d6410b9b564d76ed85f08e12d14.png

#18. Dropdown on Desktop – Remove Dropdown on Mobile

If you use a Dropdown Men on Desktop, like this

image.png.7762e0420339ff028ead235e41e1c297.png

and on Mobile, it shows this

image.png.69ff5b135a6a4a1bf4f68b81c14507cc.png

You want to remove dropdown and show all items like this without clicking “Menu”

image.png.d7b3fcba7ac4e0d4930d121db53305bf.png

You can use this code to Custom CSS box

@media only screen and (max-width: 991px) {
  .header-menu-nav-folder[data-folder="root"] {
    display: none !important;
  }
  .header-menu-nav-folder-content .header-menu-controls {
    display: none;
  }
  .header-menu-nav-folder:not([data-folder="root"]) {
    transform: unset;
    transition: unset;
  }
}

image.thumb.png.513d1c95716f4f4b9d9109f5f17f32f6.png

#19. Dropdown Menu active on Click

When you hover Dropdown Title, it will show Dropdown Item

You want, users need to click Dropdown Title to show item, instead of hovering.

First, you use this code to Custom CSS box

div.header-nav-folder-content {
    display: none;
}

image.png.d12cb5c3fce5867ad017ae165678e212.png

Next, 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() {
  $('a.header-nav-folder-title').click(function(event) {
    event.preventDefault();
    var $boxSub = $(this).closest('.header-nav-item--folder').find('.header-nav-folder-content');
    $boxSub.toggle();
  });
});
</script>

image.png.698dd46f96edd6a503ec663946795ffe.png

#20. Decrease the font size in the drop down menu in mobile view

Use CSS code

div.header-menu-controls ~ div * {
    font-size: 10px;
}

image.png.9ca5aa874ad2606a6509040b278d3d86.png

#21. Decrease the size of the drop down menu title

Use CSS code

a[data-folder-id]>div>span:nth-child(2), a.header-nav-folder-title {
    font-size: 10px;
}

image.png.d3356e8bc7655bf01795d6f0869dbb9b.png

#22. Underline dropdown item on hover

Use CSS code

div.header-nav-folder-item:hover a {
  text-decoration: underline;
}

image.png.5471b3765165f92802b8559a756ae558.png

#23. Dropdown Menu Custom Font

Suppose you uploaded custom font & declared @font-face

Next, you can use CSS code like this to Custom CSS box. Replace monospace with font what you want.

nav.header-menu-nav-list *, nav.header-nav-list * {
    font-family: monospace;
}

image.png.9f341005d3bf4187b529a5fbec47eb31.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!)

  • 2 weeks later...
Posted

#24. Dropdown Color on Blog Pages Only

Use CSS code

body[class*="type-blog"] div.header-nav-folder-content {
    background-color: #f1f !important;
}

#25. Dropdown Color on Blog Posts Only

body[class*="type-blog"].view-item div.header-nav-folder-content {
    background-color: #f1f !important;
}

#26. Dropdown Color on Blog List/Category Only

body[class*="type-blog"].view-list div.header-nav-folder-content {
    background-color: #f1f !important;
}

#27. Dropdown Menu Size (Width)

div.header-nav-folder-content {
    min-width: unset !important;
    width: 290px !important;
}

#28. Bold a part of Dropdown Nav Item

Suppose we will need to bold “Image” word

image.png.f2b325a5583789fd689911c75459cced.png

We can use code like this to Website Tools > Code Injection > Footer

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>
<script>
$(document).ready(function() {
    $(".header-nav-folder-item-content").html(function(_, html) {
        return html.replace(/(Image)/i, '<strong>$1</strong>');
    });
});
</script>

image.thumb.png.e350de5c5fb42888634bf711dd1b4fc4.png

Result

image.png.94415d96c7e7be10288fc9333b7da578.png

#29. Two Columns in Dropdown Folder

Use CSS code

div.header-nav-folder-content {
    column-count: 2;
    column-gap: 5px;
}

image.png.59a0ed5fb91eb14fce0ae1e820ee02ab.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!)

Posted

First of all, thank you! You're doing God's work here. @tuanphan

Secondly, in "#10. Add an icon before dropdown item" how do align the icon to the centre of the text? It's currently aligned to the bottom of the text and, since the icons are slightly larger than the text, it looks a bit odd.

Additionally, the icons are also too close to the text and I'd like a little gap. How can I achieve this?

Thanks for the help

Posted
11 hours ago, hmpbs said:

First of all, thank you! You're doing God's work here. @tuanphan

Secondly, in "#10. Add an icon before dropdown item" how do align the icon to the centre of the text? It's currently aligned to the bottom of the text and, since the icons are slightly larger than the text, it looks a bit odd.

Additionally, the icons are also too close to the text and I'd like a little gap. How can I achieve this?

Thanks for the help

Do you have link to site? I can check problem easier

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

Hey again @tuanphan!

I've got another question for you.

How can I make the dropdown box come out from underneath the nav bar?

image.png.4db0001e2f5db996be78f37d9713b570.png

 

Thanks for the help,

hmpbs

Posted
14 hours ago, hmpbs said:

Hey again @tuanphan!

I've got another question for you.

How can I make the dropdown box come out from underneath the nav bar?

image.png.4db0001e2f5db996be78f37d9713b570.png

 

Thanks for the help,

hmpbs

This case, each header layout/navigation item height will need a different code, do you have site url?

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 11/29/2024 at 5:10 AM, floradouville said:

Waw, amazing @tuanphan, thank you 😀 I used 2 of these already.

Now I would like the dropdown menu to align vertically from the left under the start of the word it comes under, in this case it's "Livres".

Right now, it vertically aligns from the right, with the end of the word.

Website: https://www.jeremie-mercier.com/

What should I do to fix this?

Thanks! 🙏

Capture d’écran 2024-11-28 à 23.06.40-2.png

Capture d’écran 2024-11-28 à 23.06.40.png

You can use this CSS code

div.header-nav-folder-content {
    left: -1em !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!)

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.