David Fenk David Fenk -3 years ago 88
CSS Question

How can I make this dropdown menu appear on the same line as its parent?

I'm trying to build a vertical menu with bootstrap4beta and

. I want the dropdown to appear on the right. But with
I can only make it appear in the next line and not on the same. How to do that?

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" rel="stylesheet"/>

<nav class="nav flex-column col-4 col-sm-4 col-md-4 col-lg-4 col-xl-4">
<a class="nav-link active backgroundnav" href="#">HTML</a>
<a class="nav-link backgroundnav" href="#">CSS</a>
<a class="nav-link backgroundnav" href="#">JavaScript</a>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle backgroundnav" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false">
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="Preview">
<a class="dropdown-item" href="#">Mobile Phone</a>
<a class="dropdown-item" href="#">Tablet</a>
<a class="dropdown-item" href="#">Laptop</a>
<a class="dropdown-item" href="#">Desktop</a>


Answer Source

Bootstrap 4 popper.js is positioning the dropdown so it's not easy to customize the positioning. You could override with some CSS like this, but the tricky part is figuring the "65%" value which is based on the width of the dropdown link.

.dropdown-menu-side {
    transform: translateX(65%) !important;


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download