本文介绍了Bootstrap 3 下拉菜单中心对齐不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我无法将下拉菜单与通过悬停打开下拉菜单的父级中心对齐.我试图 text-align: center 整个 .nav .navbar li 元素,但它不起作用.我试图为整个 ul.dropdown-menu 设置 margin 和 left: 50%,这是下拉菜单,但它不起作用.这是html代码:
<li><div class="btn-toolbar"><div class="btn-group"><button class="btnCustom" data-toggle="dropdown" data-hover="dropdown" data-delay="1000">我们的区别</button><ul class="下拉菜单"><li><a tabindex="-1" href="#">美国制造</a></li><li class="divider"></li><li><a tabindex="-1" href="#">Human Grade</a></li><li class="divider"></li><li><a tabindex="-1" href="#">Ingredients Fresh</a></li><li class="divider"></li><li><a tabindex="-1" href="#">USDA Meats</a></li><li class="divider"></li><li><a tabindex="-1" href="#">我们的故事</a></li><li class="divider"></li><li><a tabindex="-1" href="#">Campare</a></li>
我应该在哪个类的下拉菜单或导航导航栏导航中进行对齐,我应该设置什么?
解决方案
您可以使用变换来避免使用固定宽度:
.dropdown-menu {左:50%;右:自动;文本对齐:居中;变换:翻译(-50%,0);}
受http://css-tricks.com/centering-percentage-影响的答案宽度高度元素/
I am not able to align the dropdown to the center of the parent on which the dropdown is opened with hover. I have tried to text-align: center for the entire .nav .navbar li elements, and it doesn't work. I have tried to set margin and left: 50% for the entire ul.dropdown-menu that is the dropdown and it doesn't work. Here is the html code:
<ul class="nav navbar-nav navbar-right" id="headerDropdowns">
<li><div class="btn-toolbar">
<div class="btn-group">
<button class="btnCustom" data-toggle="dropdown" data-hover="dropdown" data-delay="1000">Our Difference</button>
<ul class="dropdown-menu">
<li><a tabindex="-1" href="#">Made in the USA</a></li>
<li class="divider"></li>
<li><a tabindex="-1" href="#">Human Grade</a></li>
<li class="divider"></li>
<li><a tabindex="-1" href="#">Ingredients Fresh</a></li>
<li class="divider"></li>
<li><a tabindex="-1" href="#">USDA Meats</a></li>
<li class="divider"></li>
<li><a tabindex="-1" href="#">Our Story</a></li>
<li class="divider"></li>
<li><a tabindex="-1" href="#">Campare</a></li>
</ul>
</div>
</li>
</ul>
In which class dropdown-menu, or nav navbar-nav, should I do the aligment, and what should I set?
解决方案
You can use transform to avoid having to use fixed widths:
.dropdown-menu {
left: 50%;
right: auto;
text-align: center;
transform: translate(-50%, 0);
}
Answer influenced by http://css-tricks.com/centering-percentage-widthheight-elements/
这篇关于Bootstrap 3 下拉菜单中心对齐不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!