Dropdown Bootstrap 3

Asked

Viewed 624 times

1

How to put a Bootstrap Dropdown menu to display on the right side? Follows a model:

inserir a descrição da imagem aqui

  • My, what an annoying model! :-)

  • hahahahahahahhaha, Sorry. It was not my intention! Just to illustrate it! kkkkkk

  • Now yes! ) +1

1 answer

1


I found an example in jsfiddle that with some adaptation I think meets what you want (I think cool and I think I’ll even use :D). I put in the snippet, click here below "Execute code snippet", that you can already see working.

$(function(){
	$(".dropdown-menu > li > a.trigger").on("click",function(e){
		var current=$(this).next();
		var grandparent=$(this).parent().parent();
		if($(this).hasClass('left-caret')||$(this).hasClass('right-caret'))
			$(this).toggleClass('right-caret left-caret');
		grandparent.find('.left-caret').not(this).toggleClass('right-caret left-caret');
		grandparent.find(".sub-menu:visible").not(current).hide();
		current.toggle();
		e.stopPropagation();
	});
	$(".dropdown-menu > li > a:not(.trigger)").on("click",function(){
		var root=$(this).closest('.dropdown');
		root.find('.left-caret').toggleClass('right-caret left-caret');
		root.find('.sub-menu:visible').hide();
	});
});
.dropdown-menu>li
{	position:relative;
	-webkit-user-select: none; /* Chrome/Safari */        
	-moz-user-select: none; /* Firefox */
	-ms-user-select: none; /* IE10+ */
	/* Rules below not implemented in browsers yet */
	-o-user-select: none;
	user-select: none;
	cursor:pointer;
}
.dropdown-menu .sub-menu {
    left: 100%;
    position: absolute;
    top: 0;
    display:none;
    margin-top: -1px;
	border-top-left-radius:0;
	border-bottom-left-radius:0;
	border-left-color:#fff;
	box-shadow:none;
}
.right-caret:after,.left-caret:after
 {	content:"";
    border-bottom: 5px solid transparent;
    border-top: 5px solid transparent;
    display: inline-block;
    height: 0;
    vertical-align: middle;
    width: 0;
	margin-left:5px;
}
.right-caret:after
{	border-left: 5px solid #ffaf46;
}
.left-caret:after
{	border-right: 5px solid #ffaf46;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet"/>
<script src="http://netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>

<div class="dropdown" style="position:relative">
	<a href="#" class="btn btn-primary dropdown-toggle" data-toggle="dropdown">Click Here <span class="caret"></span></a>
	<ul class="dropdown-menu">
		<li>
			<a class="trigger right-caret">Level 1</a>
			<ul class="dropdown-menu sub-menu">
				<li><a href="#">Level 2</a></li>
				<li>
					<a class="trigger right-caret">Level 2</a>
					<ul class="dropdown-menu sub-menu">
						<li><a href="#">Level 3</a></li>
						<li><a href="#">Level 3</a></li>
						<li>
							<a class="trigger right-caret">Level 3</a>
							<ul class="dropdown-menu sub-menu">
								<li><a href="#">Level 4</a></li>
								<li><a href="#">Level 4</a></li>
								<li><a href="#">Level 4</a></li>
							</ul>
						</li>
					</ul>
				</li>
				<li><a href="#">Level 2</a></li>
			</ul>
		</li>
		<li><a href="#">Level 1</a></li>
		<li><a href="#">Level 1</a></li>
	</ul>
</div>

  • 1

    It worked perfectly! I adapted it to my style! Tanks;)

  • Cool, now change that picture! :-)

  • Andrew, do not forget to accept the answer, so that the question is marked as resolved. Just click on the sign below the voting box. If you have any questions, please see this topic: http://meta.pt.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta Hugs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.