Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap adding a dropdown caret

http://i.imgur.com/gvNOQ7p.png

As indicated above, I want to learn to make a dropdown menu with the "dropdown-caret" (circled green in the image). I viewed source of twitter and it seems that they have it as <li class="dropdown-caret"></li>, but I couldn't produce it using the Bootstrap. Is this not included in the bootstrap, or am I doing it wrongly?

In addition, how do I align the dropdown menu to left instead of the default right? As shown in the image, the dropdown menu is aligned to left.

like image 954
Henry Cho Avatar asked May 24 '13 15:05

Henry Cho


People also ask

How do I get the caret symbol in Bootstrap?

Use carets to indicate dropdown functionality and direction. To get this functionality use the class caret with a <span> element.

How set dropdown position in Bootstrap?

By default, a dropdown menu is automatically positioned 100% from the top and along the left side of its parent. Add . dropdown-menu-right to a . dropdown-menu to right align the dropdown menu.

How can add hover effect in Bootstrap dropdown?

Answer: Use the jQuery hover() method By default, to open or display the dropdown menu in Bootstrap you have to click on the trigger element. However, if you want to show the dropdown on mouseover instead of click you can do it with little customization using the CSS and jQuery.

How do I add a dropdown symbol in HTML?

Use any element to open the dropdown menu, e.g. a <button>, <a> or <p> element. Use a container element (like <div>) to create the dropdown menu and add the dropdown links inside it. Wrap a <div> element around the button and the <div> to position the dropdown menu correctly with CSS.


1 Answers

Twitter bootstrap adds the caret by default if you are using dropdowns within a navigation bar. These are the CSS rules:

.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: '';
}

So make sure you have this DOM structure or copy the style.

Hope this helps!

like image 174
cortex Avatar answered Sep 22 '22 19:09

cortex