How to remove the arrow in dropdown in Bootstrap 4

2019-02-02 19:16发布

I am using Bootstrap 4. I tried to remove the arrow in dropdown.

The answers I found for Bootstrap 3 do not work any more.

The jsfiddle is here.

<div class="dropdown open">
  <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
    Dropdown
  </button>
  <div class="dropdown-menu" aria-labelledby="dropdownMenu1">
    <a class="dropdown-item" href="#">Action</a>
    <a class="dropdown-item" href="#">Another action</a>
  </div>
</div>

10条回答
等我变得足够好
2楼-- · 2019-02-02 20:02

If you remove fit the dropdown-toggle class as below, all the dropdown buttons on your system will no longer have the caret.

.dropdown-toggle::after {
    display:none;
}

But maybe that's not what you want, so to remove just the specific button, we're going to insert a class called: remoecaret, and we'll fit the class: dropdown-toggle as follows:

.removecaret.dropdown-toggle::after {
    display: none;
}

and our html looks something like:

<div class="btn-group">
  <button class="btn btn-outline-secondary btn-sm dropdown-toggle removecaret" data-toggle="dropdown">
    <i class="fa fa-bars" aria-hidden="true"></i>
  </button>
  <ul class="dropdown-menu dropdown-menu-right">
    <li><a href="#"><a href="#"><i class="fa fa-cog" aria-hidden="true"></i>&nbsp;Edit</a></li>
  </ul>
</div>
查看更多
我命由我不由天
3楼-- · 2019-02-02 20:02

Oh, I found the way:

.dropdown-toggle::after {
    content: none;
}
查看更多
\"骚年 ilove
4楼-- · 2019-02-02 20:04

With css, you could just do that:

.dropdown-toggle::after {
    display:none;
}
查看更多
甜甜的少女心
5楼-- · 2019-02-02 20:05

If you are interested in replacing the arrow with another Icon (such as, FontAwesome) you would just need to remove the border on the pseudo element of .dropdown-toggle

.dropdown-toggle::after { border: none; }
查看更多
登录 后发表回答