Bootstrap 3 Template
This is a simple Twitter Bootstrap 3 template. You can fork it to get a ready to use Bootstrap 3 fiddle.
HTML
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
<section>
<button class="btn dropdown-toggle" type="button" data-toggle="dropdown">User Name<span class="caret"></span></button>
<ul class="dropdown-menu">
<li><a href="#">Profile</a></li>
<li><a href="#">Logout</a></li>
</ul>
</section>
CSS
/* Latest compiled and minified CSS included as External Resource*/
/* Optional theme */
@import url('//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap-theme.min.css');
body {
margin: 10px;
}
section {
position:relative
}
JavaScript
$('.dropdown-toggle').click(function () {
$('.dropdown-menu').slideToggle();
});
$(document).mouseup(function (e)
{
if (!$(".dropdown-menu").is(e.target) && !$(".dropdown-toggle").is(e.target) && $(".dropdown-menu").has(e.target).length === 0 && $(".dropdown-toggle").has(e.target).length === 0)
{
$(".dropdown-menu").slideUp()
}
});