What's the mystery of the Bootstrap dropdown menu triangle?

后端 未结 3 982
说谎
说谎 2021-02-05 13:33

I\'m trying to understand the difference between Twitter Bootstrap dropdown menus when they are included within a navbar and when they are not.

When they are included in

相关标签:
3条回答
  • 2021-02-05 13:45

    The triangle can be generated by the following syntax:

        <b class="caret dropdown-toggle"></b>
    
    0 讨论(0)
  • 2021-02-05 13:49

    There are two styles applied to the dropdown menu when inside the nav element. They are as follows:

    .navbar .nav > li > .dropdown-menu::before {
       position: absolute;
       top: -7px;
       left: 9px;
       display: inline-block;
       border-right: 7px solid transparent;
       border-bottom: 7px solid #CCC;
       border-left: 7px solid transparent;
       border-bottom-color: rgba(0, 0, 0, 0.2);
       content: '';
     }
     .navbar .nav > li > .dropdown-menu::after {
        position: absolute;
        top: -6px;
        left: 10px;
        display: inline-block;
        border-right: 6px solid transparent;
        border-bottom: 6px solid white;
        border-left: 6px solid transparent;
        content: '';
      }
    

    They create two triangles on top of each other one light grey, the other dark grey. If you use chrome developer tools you can inspect these elements and turn off different styles to get a feel for what they are doing. These styles are not applied without the navbar

    0 讨论(0)
  • 2021-02-05 13:55

    Just add this to the CSS and you will be able to use dropdown menu arrow without placing the dropdown inside a nav bar

    .dropdown-menu:before {
       position: absolute;
       top: -7px;
       left: 9px;
       display: inline-block;
       border-right: 7px solid transparent;
       border-bottom: 7px solid #CCC;
       border-left: 7px solid transparent;
       border-bottom-color: rgba(0, 0, 0, 0.2);
       content: '';
     }
    
    .dropdown-menu:after {
        position: absolute;
        top: -6px;
        left: 10px;
        display: inline-block;
        border-right: 6px solid transparent;
        border-bottom: 6px solid white;
        border-left: 6px solid transparent;
        content: '';
      }
    
    .dropdown-menu:before, .dropdown-menu.pull-right:before {
    right: 12px;
    left: auto;
    }
    
    .dropdown-menu::after, .dropdown-menu.pull-right:after {
    right: 13px;
    left: auto;
    }
    
    0 讨论(0)
提交回复
热议问题