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

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

问题描述

我无法将下拉列表与使用鼠标悬停在其上打开下拉列表的父级中心对齐。我试图文本对齐:中心为整个.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天全站免登陆