Reputation: 420
How do i center the dropdown menu on the screen (small screens in particular).
<div class="dropdown">
<a class="btn btn-secondary dropdown-toggle" href="#" role="button" id="dropdownMenuLink" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown link
</a>
<div class="dropdown-menu" aria-labelledby="dropdownMenuLink">
<a class="dropdown-item" href="#">Action</a>
<a class="dropdown-item" href="#">Another action</a>
<a class="dropdown-item" href="#">Something else here</a>
</div>
</div>
I have tried to add position:absolute, left:0
etc. however without any luck..
Upvotes: 0
Views: 384
Reputation: 24
You can use transform:
Example:
.dropdown-menu {
left: 50%;
right: auto;
text-align: center;
transform: translate(-50%, 0);
}
If you need more info, you can read more about it on the CSS-tricks
Upvotes: 1
Reputation: 67778
In this case (in a media query) you can use position: fixed
, an appropriate top
value (equal to the height of the navbar), and for the horizontal centering left: 50%
and transform: translateX(-50%);
Upvotes: 0