I am using the Bootstrap 4 dropdown option.
I wanted to add an up arrow for the dropdown menu in the top left.
In Bootstrap 3, we have a caret markup on the button, so we can add the arrow to the dropdown menu.
But in Bootstrap 4, we don't have a caret markup, using the dropdown-toggle
class only caret is added.
How can we add arrow to dropdown menu here?
I added the Bootstrap 3 example link:
https://www.bootply.com/QD8FO89DcY
The same functionality is needed in Bootstrap 4.
In Bootstrap 4 it has been removed, add that caret/arrow by yourself, please have a look at the below working snippet, where I have added it with a custom CSS.
.dropdown-menu-arrow {
top: -25px;
left: 50%;
width: 0;
height: 0;
position: relative;
}
.dropdown-menu-arrow:before,
.dropdown-menu-arrow:after {
content: "";
position: absolute;
display: block;
width: 0;
height: 0;
border-width: 7px 8px;
border-style: solid;
border-color: transparent;
z-index: 1001;
}
.dropdown-menu-arrow:after {
bottom: -18px;
right: -8px;
border-bottom-color: #fff;
}
.dropdown-menu-arrow:before {
bottom: -17px;
right: -8px;
border-bottom-color: rgba(0,0,0,.15);
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<div class="btn-group">
<div class="btn-group">
<button id="customDropdown" type="button" class="btn btn-outline-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</button>
<div class="dropdown-menu" aria-labelledby="customDropdown">
<span class="dropdown-menu-arrow"></span>
<a class="dropdown-item" href="#">Dropdown link</a>
<a class="dropdown-item" href="#">Dropdown link</a>
</div>
</div>
</div>
Try this
.dropdown-menu::before {
border-bottom: 9px solid rgba(0, 0, 0, 0.2);
border-left: 9px solid rgba(0, 0, 0, 0);
border-right: 9px solid rgba(0, 0, 0, 0);
content: "";
display: inline-block;
left: 5%; /* position */
position: absolute;
top: -8px;
}
.dropdown-menu::after {
border-bottom: 8px solid #FFFFFF;
border-left: 9px solid rgba(0, 0, 0, 0);
border-right: 9px solid rgba(0, 0, 0, 0);
content: "";
display: inline-block;
left: 5%; /* position */
position: absolute;
top: -7px;
}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css">
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js"></script>
<div class="btn-group">
<div class="btn-group">
<button id="customDropdown" type="button" class="btn btn-outline-secondary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Dropdown
</button>
<div class="dropdown-menu" aria-labelledby="customDropdown">
<a class="dropdown-item" href="#">Dropdown link</a>
<a class="dropdown-item" href="#">Dropdown link</a>
</div>
</div>
/* for shadow */
.dropdown-menu::before {
border-bottom: 9px solid rgba(0, 0, 0, 0.2);
border-left: 9px solid rgba(0, 0, 0, 0);
border-right: 9px solid rgba(0, 0, 0, 0);
content: "";
display: inline-block;
left: 5%; /* position */
position: absolute;
top: -8px;
}
.dropdown-menu::after {
border-bottom: 8px solid #FFFFFF;
border-left: 9px solid rgba(0, 0, 0, 0);
border-right: 9px solid rgba(0, 0, 0, 0);
content: "";
display: inline-block;
left: 5%; /* position */
position: absolute;
top: -7px;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With