x

HTML code for a drop down button

Can someone help please with some code. I need to place a button on my page with a drop down options menu. Weebly doesn't give an option for this and has only told me to go to W3 Schools for tutorials. I have done this but no matter what I do the code doesn't seem to drop down once I place in my weebly site page. Does anyone have any code they could share that works on a weebly site please?

4,174 Views
Message 1 of 13
Report
12 REPLIES 12
Square

What code are you using and what's the URL of the page of your site where you added this, @sarahcarr?

4,157 Views
Message 2 of 13
Report

Hi Adam

I don't think it is right but the code I am using is -


<div class="dropdown">
<button class="dropbtn">Hibiscus Coast Business Directory Sections</button>
<div class="dropdown-content">
<a href="https://www.linku2hibiscuscoast.co.nz/hibiscus-coast-local-business-quick-guide.html">Coast Local Quick Business Links</a>
<a href="https://www.linku2hibiscuscoast.co.nz/hibicus-coast-business-features.html">Business Features</a>
<a href="#">Link 3</a>
</div>
</div>
<br />
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.dropbtn {
background-color: #F67606;
color: white;
padding: 16px;
font-size: 16px;
border: none;
}

.dropdown {
position: relative;
display: inline-block;
}

.dropdown-content {
display: none;
position: absolute;
background-color: #f1f1f1;
min-width: 300px;
box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
z-index: 1;
}

.dropdown-content a {
color: black;
padding: 12px 16px;
text-decoration: none;
display: block;
}

.dropdown-content a:hover {background-color: #ddd;}

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

.dropdown:hover .dropbtn {background-color: #0056d6;}
</style>
</head>
<body>

<h3>Click Above for Business Directory Sections</h3>
<p>These lead to our second level categories</p>

<div class="dropdown">
<button class="dropbtn">Dropdown</button>
<div class="dropdown-content">
<a href="#">Link 1</a>
<a href="#">Link 2</a>
<a href="#">Link 3</a>
</div>
</div>

</body>
</html>

For some reason it only works showing two buttons which is annoying and the top button is the only one that works - I did at one stage get it to work with 4 menus but I have about 17 to add to the drop down.

I was going to do a hover button but understand this is not good for mobile viewers so think perhaps it is best to have a button that is clicked on for the drop down to appear. I'd really appreciate your help

Sarah

4,143 Views
Message 2 of 13
Report
Square

Try using just this:

<style>
	.dropbtn {
		background-color: #F67606;
		color: white;
		padding: 16px;
		font-size: 16px;
		border: none;
	}
	.dropdown {
		position: relative;
		display: inline-block;
	}
	.dropdown-content {
		display: none;
		position: absolute;
		background-color: #f1f1f1;
		min-width: 300px;
		box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
		z-index: 1;
	}
	.dropdown-content a {
		color: black;
		padding: 12px 16px;
		text-decoration: none;
		display: block;
	}
	.dropdown-content a:hover {background-color: #ddd;}
	.dropdown:hover .dropdown-content {display: block;}
	.dropdown:hover .dropbtn {background-color: #0056d6;}
</style>
<div class="dropdown">
	<button class="dropbtn">Hibiscus Coast Business Directory Sections</button>
	<div class="dropdown-content">
		<a href="https://www.linku2hibiscuscoast.co.nz/hibiscus-coast-local-business-quick-guide.html">Coast Local Quick Business Links</a>
		<a href="https://www.linku2hibiscuscoast.co.nz/hibicus-coast-business-features.html">Business Features</a>
		<a href="#">Link 3</a>
	</div>
</div>

Some of the tags that are included with what you have now could break the display of the site.

4,141 Views
Message 2 of 13
Report

Hi Adam

Thanks for your help - unfortunately that code doesn't work either - I've put it on this page so you can check 

https://www.linku2hibiscuscoast.co.nz/linku2-hibiscus-coast-contact.html

Sarah

4,121 Views
Message 2 of 13
Report
Square

Try this instead:

<style>
	#512019927167895105
	{
		overflow: visible !important;
	}
	.dropbtn {
		background-color: #F67606;
		color: white;
		padding: 16px;
		font-size: 16px;
		border: none;
	}
	.dropdown {
		position: relative;
		display: inline-block;
	}
	.dropdown-content {
		display: none;
		position: absolute;
		background-color: #f1f1f1;
		min-width: 300px;
		box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
		z-index: 1;
	}
	.dropdown-content a {
		color: black;
		padding: 12px 16px;
		text-decoration: none;
		display: block;
	}
	.dropdown-content a:hover {background-color: #ddd;}
	.dropdown:hover .dropdown-content {display: block;}
	.dropdown:hover .dropbtn {background-color: #0056d6;}
</style>
<div class="dropdown">
	<button class="dropbtn">Hibiscus Coast Business Directory Sections</button>
	<div class="dropdown-content">
		<a href="https://www.linku2hibiscuscoast.co.nz/hibiscus-coast-local-business-quick-guide.html">Coast Local Quick Business Links</a>
		<a href="https://www.linku2hibiscuscoast.co.nz/hibicus-coast-business-features.html">Business Features</a>
		<a href="#">Link 3</a>
	</div>
</div>

Our embed code element hides overflow by default, so the extra code I added will override that.

4,113 Views
Message 2 of 13
Report

4,104 Views
Message 2 of 13
Report
Square

Did you paste this into a new Embed Code element? The code update I gave specific to the element it was in before, since we assign a unique ID to each element. 

Try this instead:

<style>
	.wcustomhtml
	{
		overflow: visible !important;
	}
	.dropbtn {
		background-color: #F67606;
		color: white;
		padding: 16px;
		font-size: 16px;
		border: none;
	}
	.dropdown {
		position: relative;
		display: inline-block;
	}
	.dropdown-content {
		display: none;
		position: absolute;
		background-color: #f1f1f1;
		min-width: 300px;
		box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
		z-index: 1;
	}
	.dropdown-content a {
		color: black;
		padding: 12px 16px;
		text-decoration: none;
		display: block;
	}
	.dropdown-content a:hover {background-color: #ddd;}
	.dropdown:hover .dropdown-content {display: block;}
	.dropdown:hover .dropbtn {background-color: #0056d6;}
</style>
<div class="dropdown">
	<button class="dropbtn">Hibiscus Coast Business Directory Sections</button>
	<div class="dropdown-content">
		<a href="https://www.linku2hibiscuscoast.co.nz/hibiscus-coast-local-business-quick-guide.html">Coast Local Quick Business Links</a>
		<a href="https://www.linku2hibiscuscoast.co.nz/hibicus-coast-business-features.html">Business Features</a>
		<a href="#">Link 3</a>
	</div>
</div>
4,092 Views
Message 2 of 13
Report

Sorry for the delay - yes thanks Adam that seems to work now! Thank you for your help

Sarah

4,067 Views
Message 2 of 13
Report
Square

Awesome! Glad to hear that. Smiley Happy

4,058 Views
Message 2 of 13
Report

Hi Adam

Tried the code and it works on desktop but not on mobile, any tip on how to make it work on phone and tablets?

1,916 Views
Message 2 of 13
Report
Square

How is it not working on mobile for you, @rafael56?

1,909 Views
Message 2 of 13
Report

Is this still active?

I need to make two buttons have drop down menus that lead to individual pages. How can this be done? Thank you!

1,561 Views
Message 2 of 13
Report