Bootstrap 3下拉菜单中心对齐不工作 [英] Bootstrap 3 dropdown menu center align not working

查看:95
本文介绍了Bootstrap 3下拉菜单中心对齐不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法将下拉列表对齐到使用悬停打开下拉菜单的父级的中心。我试图text-align:中心为整个.nav .navbar li元素,它不工作。我试图设置边距和左:50%的整个ul.dropdown菜单是下拉菜单,它不工作。这是html代码:

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>

在类下拉菜单或nav navbar-nav中,应该设置吗?

In which class dropdown-menu, or nav navbar-nav, should I do the aligment, and what should I set?

推荐答案

您可以使用transform避免使用固定宽度:

You can use transform to avoid having to use fixed widths:

.dropdown-menu {
  left: 50%;
  right: auto;
  text-align: center;
  transform: translate(-50%, 0);
}

http://css-tricks.com/centering-percentage-widthheight-elements/

这篇关于Bootstrap 3下拉菜单中心对齐不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆