How to remove the arrow in dropdown in Bootstrap 4?

后端 未结 13 1295
谎友^
谎友^ 2020-12-23 15:47

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.



        
相关标签:
13条回答
  • 2020-12-23 16:18

    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; }
    
    0 讨论(0)
  • 2020-12-23 16:18

    I was using the accepted answer for quite a while in my project but just now stumbled across a variable used by bootstrap:

    $enable-caret: true !default;
    

    If you set this to false then the caret will be removed without having to do any custom code.

    My project was Ruby/Rails so I was using the bootstrap-rubygem. I changed the variable by importing a custom-variables.scss with the above variable set to false in my application.scss BEFORE the bootstrap.scss file/files.

    0 讨论(0)
  • 2020-12-23 16:19

    With css, you could just do that:

    .dropdown-toggle::after {
        display:none;
    }
    
    0 讨论(0)
  • 2020-12-23 16:23

    remove the "dropdown-toggle" class

    0 讨论(0)
  • 2020-12-23 16:24

    I don't recommend any of the existing answers because:

    • .dropdown-toggle has more styling than just the caret. Removing the class from the element causes styling issues.

    • Overriding .dropdown-toggle doesn't make sense. Just because you don't need a caret on some particular element, doesn't mean you won't need one later.

    • ::after doesn't cover dropdown variants (some use ::before).

    Use a custom .caret-off in the same element as your .dropdown-toggle element:

    .caret-off::before {
        display: none;
    }
    .caret-off::after {
        display: none;
    }
    
    0 讨论(0)
  • 2020-12-23 16:26

    This works on bootsrap4 and ng-bootstrap.

    .dropdown-toggle:after {
        display: none;
    }
    
    0 讨论(0)
提交回复
热议问题