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.
Use carets to indicate dropdown functionality and direction. To get this functionality use the class caret with a <span> element.
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.
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.
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.
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!
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