如何左对齐引导3下拉菜单?

时间:2022-11-20 07:35:45

如何左对齐引导3下拉菜单?

In the above image MenuItems are align to right side of the MyMenu, I needed to left align the MenuItems of MyMenu (I mean it must aligned to left edge of MyMenu), I try to use pull-left and pull-right class like <ul class="dropdown-menu pull-left" role="menu"> with my code, but it doesn't work. anyone has an idea how to do this ?

在上面的图像对齐MyMenu右边的菜单项,我需要左对齐的菜单项MyMenu(我的意思是它必须对齐左边缘MyMenu),我尝试使用pull-left扯类像< ul类=”下拉菜单pull-left”=“菜单”>角色和我的代码,但它不工作。有人知道怎么做吗?

Here is my code

这是我的代码

<!-- Static navbar -->
    <nav class="navbar navbar-inverse" role="navigation">
      <div class="container-fluid">
        <div class="navbar-header">
          <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
          </button>
          <a class="navbar-brand" href="#"></a>
        </div>
        <div id="navbar" class="navbar-collapse collapse">

              <ul class="nav navbar-nav navbar-right text-uppercase">
                <li><a id="Home" href="index.html">Home</a></li>
                <!-- Visa drapdown-->
                <li class="dropdown">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown"> My Menu <span class="caret"></span></a>

                  <ul class="dropdown-menu pull-left" role="menu">
                    <li><a href="#">Menu Item 01</a></li>
                      <li><a href="#">Menu Item 01</a></li>
                      <li><a href="#">Menu Item 02</a></li>
                      <li><a href="#">Menu Item 03</a></li>
                      <li><a href="#">Menu Item 04</a></li>
                      <li><a href="#"></a></li>

                    </ul>

                  </li>

            </div><!--/.nav-collapse -->
          </div><!--/.container-fluid -->
        </nav>

4 个解决方案

#1


14  

Adding this style element to the dropdown <ul> will align the dropdown to the left side of the menu item:

将此样式元素添加到dropdown

    将使下拉菜单项与菜单项的左侧对齐:

left:0;

See this Bootply which targets the .dropdown-menu.pull-left and adds a left:0;. This should solve your problem.

看到这个引导层,目标是。下拉菜单。拉左,加左:0;这应该能解决你的问题。


Update

更新

I see that Bootstrap has deprecated pull-right and pull-left as of Bootstrap 3.1.0. Use dropdown-menu-left class to use built-in Bootstrap css to align the dropdown on the left edge so you don't need extra CSS. See this updated Bootply

我看到Bootstrap已经弃用了Bootstrap 3.1.0的拉右和下拉。使用dropdownmenu -left类使用内置的Bootstrap css将下拉列表对齐到左边缘,这样就不需要额外的css了。看到这个更新bootp

#2


29  

for Twitter Bootstrap 3

<div class="dropdown-menu pull-right">
    <!-- write your code here -->
</div>

hope it helps :)

希望它能帮助:)

#3


10  

For Bootstrap 3.1.0 or above use .dropdown-menu-left or .dropdown-menu-right to display the drop down menus right or left side of the parent menu. In your case try following.

对于Bootstrap 3.1.0或以上使用. dropdownmenu -left或. dropdownmenu -right来显示下拉菜单的右或左侧菜单。在你的案例中,试着跟随。

 <li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown"> My Menu <span class="caret"></span></a>
      <ul class="dropdown-menu dropdown-menu-left" role="menu">
       <!-- write your code here -->
      </ul>
 </li>

Bootstrap is BEST

引导是最好的

#4


3  

Change navbar-right to navbar-left and add a pull-right class to the UL.

将navbar-right改为navbar-left,并向UL添加一个pull-right类。

<ul class="nav navbar-nav navbar-left text-uppercase pull-right">

Check out the JSfiddle for an example.

请查看JSfiddle的示例。

http://jsfiddle.net/eqcpLj6k/1/

http://jsfiddle.net/eqcpLj6k/1/

#1


14  

Adding this style element to the dropdown <ul> will align the dropdown to the left side of the menu item:

将此样式元素添加到dropdown

    将使下拉菜单项与菜单项的左侧对齐:

left:0;

See this Bootply which targets the .dropdown-menu.pull-left and adds a left:0;. This should solve your problem.

看到这个引导层,目标是。下拉菜单。拉左,加左:0;这应该能解决你的问题。


Update

更新

I see that Bootstrap has deprecated pull-right and pull-left as of Bootstrap 3.1.0. Use dropdown-menu-left class to use built-in Bootstrap css to align the dropdown on the left edge so you don't need extra CSS. See this updated Bootply

我看到Bootstrap已经弃用了Bootstrap 3.1.0的拉右和下拉。使用dropdownmenu -left类使用内置的Bootstrap css将下拉列表对齐到左边缘,这样就不需要额外的css了。看到这个更新bootp

#2


29  

for Twitter Bootstrap 3

<div class="dropdown-menu pull-right">
    <!-- write your code here -->
</div>

hope it helps :)

希望它能帮助:)

#3


10  

For Bootstrap 3.1.0 or above use .dropdown-menu-left or .dropdown-menu-right to display the drop down menus right or left side of the parent menu. In your case try following.

对于Bootstrap 3.1.0或以上使用. dropdownmenu -left或. dropdownmenu -right来显示下拉菜单的右或左侧菜单。在你的案例中,试着跟随。

 <li class="dropdown">
    <a href="#" class="dropdown-toggle" data-toggle="dropdown"> My Menu <span class="caret"></span></a>
      <ul class="dropdown-menu dropdown-menu-left" role="menu">
       <!-- write your code here -->
      </ul>
 </li>

Bootstrap is BEST

引导是最好的

#4


3  

Change navbar-right to navbar-left and add a pull-right class to the UL.

将navbar-right改为navbar-left,并向UL添加一个pull-right类。

<ul class="nav navbar-nav navbar-left text-uppercase pull-right">

Check out the JSfiddle for an example.

请查看JSfiddle的示例。

http://jsfiddle.net/eqcpLj6k/1/

http://jsfiddle.net/eqcpLj6k/1/