Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

dropdown menu like Facebooks (how?)

Featured Replies

I know how to create a drop down menu with :hover in CSS but what I want to know is how I can have a drop down menu so that when you click on the link/button it comes down, and stays down even if you move the mouse off it, then when you click anywhere on the screen it disappears.

 

An example would be Facebook, they use this on their 'down arrow' next to 'Home' in the top right corner.

 

I've tried using the onclick event with javascript, and I'm sure this must be part of the process (if not please correct), but I can't find a solution to being able to click anywhere on the screen to remove the menu.

  • Author

I used the jQuery library to work this out.

 

<!DOCTYPE html>
<html>

<head>

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>

<script type="text/javascript" >
$(document).ready(function(){
$("html").click(function(){
	$("#div").hide();
});
$("#buttonDiv").click(function(){
	$("#div").slideDown(200); 
});
$('#div').click(function(){
	event.stopPropagation();
});
});
</script>

<style type="text/css">
body {

}

button {
margin: 0;
padding: 0;	
}

#buttonDiv {
border: 1px solid black;
height: 20px;
width: 100px;	
}
#buttonDiv:hover {
cursor: pointer;
}

#div {
border: 1px solid black;

width: 98px;
height: 100px;
top: 100px;
position: relative;
}
</style>

</head>

<body>

<button type="button" id="buttonDiv">Show</button>

<div id="div">
<a href="#">something</a>
</div>



</body>
</html>


</script>

  • Author

You'll need some absolute positioning on the dropdown so it overlaps content

Yeah I found that out when I implemented it into my site, I needed to use absolute positioning and a z-index of 2 so that it would be on top of everything else.

 

One thing I can't figure out... I used the 'html' element so that any click outside the div would hide it, but it doesn't work if I click inside an iFrame... any ideas?

  • Author

An iframe is a completely separate document with its own DOM.

is there no way of doing it then? that would really suck for me

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.