Jump to content

[Share] How to create a Dropdown

Recommended Posts

Posted

Description

  • A Dropdown with some options
  • Click on each option will open new page in new tab

You can follow these steps.

#1. First, Add a Code Block

image.png.db7ef1a2320792b9614941f9054f1a02.png

#2. Use this code into Code Block

<div class="dropdown">
        <button class="dropdown-button">Buy the Book</button>
        <div class="dropdown-menu">
            <a href="https://www.amazon.com" target="_blank" class="dropdown-option">Amazon</a>
            <a href="https://www.apple.com/apple-books/" target="_blank" class="dropdown-option">Apple Books</a>
            <a href="https://www.barnesandnoble.com" target="_blank" class="dropdown-option">Barnes & Noble</a>
        </div>
</div>
<style>
    .dropdown {
    position: relative;
    display: inline-block;
}

.dropdown-button {
    padding: 10px 20px;
    font-size: 16px;
    background-color: #007BFF;
    color: white;
    border: none;
    border-radius: 50px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 200px;
    text-align: left;
}

.dropdown-button::after {
    content: "▼";
    margin-left: auto;
    font-size: 12px;
}

.dropdown-menu {
    display: none;
    position: absolute;
    top: 100%;
    left: 0;
    background-color: white;
    border: 1px solid #ccc;
    border-radius: 4px;
    box-shadow: 0px 4px 6px rgba(0, 0, 0, 0.1);
    z-index: 1000;
    width: 100%;
}

.dropdown:hover .dropdown-menu {
    display: block;
}

.dropdown-option {
    display: block;
    padding: 3px 15px;
    color: #333;
    text-decoration: none;
    font-size: 14px;
}

.dropdown-option:hover {
    background-color: #f0f0f0;
}
</style>

image.thumb.png.9416003e813c56c60aa47c226eeab2fd.png

#3. Result

image.thumb.png.56c4d9296c2ca0033b02d0605914e76f.png

#4. Customize

To change dropdown text/url, change these

image.thumb.png.40b00a1ed83c060e8f007683ce67e1d0.png

To change dropdown style, change these

image.png.076f07567f9462ae203751e9b4d21c10.png

image.png.1f6721f72c5dc81ff298aeef3c7a5547.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 1
  • Views 131
  • Created
  • Last Reply

Top Posters In This Topic

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.