Twitter Bootstrap导航组件中的下拉菜单在下拉菜单的顶部有一个“提示”。
如何在常规下拉菜单中添加提示?
<div class="dropdown">
<a href="#" data-toggle="dropdown">
Click me
</a>
<ul class="dropdown-menu" role="menu" aria-labelledby="dLabel">
<li><a tabindex="-1" href="#">Action</a></li>
</ul>
</div>
答案 0 :(得分:3)
添加此CSS:
.dropdown-menu:before {
position: absolute;
top: -5px;
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: -3px;
left: 10px;
display: inline-block;
border-right: 6px solid transparent;
border-bottom: 6px solid #ffffff;
border-left: 6px solid transparent;
content: '';
}
我从nav
下拉样式中获取了它并更改了几个值。根据您的需求调整应该很容易。
答案 1 :(得分:1)
这是Bootstrap 4的更新解决方案。只需应用以下CSS并在菜单中添加dropdown-menu-tip-[n|ne|nw|s|se|sw]
修饰符。
[class*="dropdown-menu-tip-"]::after {
content: '';
position: absolute;
width: .5rem;
height: .5rem;
background-color: white; /* For SCSS use $dropdown-bg */
border: solid 1px rgba(0, 0, 0, .15); /* For SCSS use $dropdown-bg */
border-bottom: none;
border-left: none;
}
/* North */
.dropdown-menu-tip-n::after {
top: calc(-.25rem - 1px);
left: calc(50% - .25rem);
transform: rotate(-45deg);
}
/* Northeast */
.dropdown-menu-tip-ne::after {
top: calc(-.25rem - 1px);
right: 1rem;
transform: rotate(-45deg);
}
/* Northwest */
.dropdown-menu-tip-nw::after {
top: calc(-.25rem - 1px);
left: 1rem;
transform: rotate(-45deg);
}
/* South */
.dropdown-menu-tip-s::after {
left: calc(50% - .25rem);
bottom: calc(-.25rem - 1px);
transform: rotate(135deg);
}
/* Southeast */
.dropdown-menu-tip-se::after {
right: 1rem;
bottom: calc(-.25rem - 1px);
transform: rotate(135deg);
}
/* Southwest */
.dropdown-menu-tip-sw::after {
left: 1rem;
bottom: calc(-.25rem - 1px);
transform: rotate(135deg);
}
演示:https://codepen.io/claviska/pen/LzvMpx
来源:https://www.abeautifulsite.net/adding-a-checked-state-to-bootstrap-4-dropdown-menus