如何将Zurb Foundation顶部栏杆导航器居中?

时间:2022-12-06 17:01:35

The top bar nav on my site is left aligned like this:

我网站上的顶部栏导航左对齐,如下所示:

| Home | aveoTSD | Silent Nite          |

I would like to center the top bar nav like this:

我想像这样中心顶部栏导航:

|          Home | aveoTSD | Silent Nite          |

Center it exactly like the red bar with "Example" text.

将它居中,就像带有“示例”文本的红色条一样。

Here is my css.

这是我的CSS。

4 个解决方案

#1


18  

You can do it by adding this to your CSS (and preferably removing conflicting styles):

您可以通过将其添加到CSS(最好删除冲突的样式)来实现:

.top-bar-section ul {display: table; margin: 0 auto;}
.top-bar-section ul li {display: table-cell;}

#2


5  

Found this to be helpful: https://github.com/zurb/foundation/issues/1598

发现这有用:https://github.com/zurb/foundation/issues/1598

Set the container of the navigation to: text-align:center;

将导航容器设置为:text-align:center;

Then for the navigation itself, set the display to: display:inline-block;

然后对于导航本身,将显示设置为:display:inline-block;

Hope that helps!

希望有所帮助!

#3


2  

Here is the best solution I've found that works for all resize events. It centers the Foundation 5 Top-bar elements.

这是我发现适用于所有调整大小事件的最佳解决方案。它以Foundation 5 Top-bar元素为中心。

SCSS:

nav.top-bar:not(.expanded) {
            text-align: center;
            section.top-bar-section { display: inline-block; }
                           }

HTML:

<div class="contain-to-grid">
<nav class="top-bar" data-topbar>
    <ul class="title-area">
        <li class="name">
            <h1><a href="#"></a></h1>
        </li>
        <!-- Remove the class "menu-icon" to get rid of menu icon. Take out "Menu" to just have icon alone -->
        <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
    </ul>

    <section class="top-bar-section">
        <ul>
            <li><%= link_to 'LINK 1', root_path %></li>
            <li class="divider"></li>
            <li><%= link_to 'LINK2', link_path %></li>
            <li class="divider"></li>
            <li class="has-dropdown">
                <%= link_to 'Droping', "#" %>
                <ul class="dropdown">
                    <li><label>Label:</label></li>
                    <li><%= link_to 'DROP 1', drop_path %></li>
                    <li class="divider"></li>
                    <li><%= link_to 'DROP 2', drop_path %></li>
                </ul>
            </li>
            <li class="divider"></li>
        </ul>
    </section>
</nav>

#4


0  

Using the above example, I make a few tweaks. The above centers everything. The adjustments below centers the topbar, left justifies the text on drop-downs and centers the "hamburger" / menu-icon when in mobile:

使用上面的例子,我做了一些调整。以上是一切。下面的调整将中心放在顶部栏中,左侧将文本放在下拉列表中,并在移动设备中将“汉堡包”/菜单图标置于中心位置:

/* center topbar */
/* set alignment to center for small screens */
nav.top-bar { text-align:center; }
nav.top-bar:not(.expanded) {
        text-align: center;
        section.top-bar-section { 
            /* align drop down menu text to left on large screens */
            text-align:left; 
            display: inline-block;

         }


}
/* center the mobile hamburger menu */
.top-bar .toggle-topbar.menu-icon {
 padding: 0;
 right: 50%;
 margin-right: -36px;
}

#1


18  

You can do it by adding this to your CSS (and preferably removing conflicting styles):

您可以通过将其添加到CSS(最好删除冲突的样式)来实现:

.top-bar-section ul {display: table; margin: 0 auto;}
.top-bar-section ul li {display: table-cell;}

#2


5  

Found this to be helpful: https://github.com/zurb/foundation/issues/1598

发现这有用:https://github.com/zurb/foundation/issues/1598

Set the container of the navigation to: text-align:center;

将导航容器设置为:text-align:center;

Then for the navigation itself, set the display to: display:inline-block;

然后对于导航本身,将显示设置为:display:inline-block;

Hope that helps!

希望有所帮助!

#3


2  

Here is the best solution I've found that works for all resize events. It centers the Foundation 5 Top-bar elements.

这是我发现适用于所有调整大小事件的最佳解决方案。它以Foundation 5 Top-bar元素为中心。

SCSS:

nav.top-bar:not(.expanded) {
            text-align: center;
            section.top-bar-section { display: inline-block; }
                           }

HTML:

<div class="contain-to-grid">
<nav class="top-bar" data-topbar>
    <ul class="title-area">
        <li class="name">
            <h1><a href="#"></a></h1>
        </li>
        <!-- Remove the class "menu-icon" to get rid of menu icon. Take out "Menu" to just have icon alone -->
        <li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
    </ul>

    <section class="top-bar-section">
        <ul>
            <li><%= link_to 'LINK 1', root_path %></li>
            <li class="divider"></li>
            <li><%= link_to 'LINK2', link_path %></li>
            <li class="divider"></li>
            <li class="has-dropdown">
                <%= link_to 'Droping', "#" %>
                <ul class="dropdown">
                    <li><label>Label:</label></li>
                    <li><%= link_to 'DROP 1', drop_path %></li>
                    <li class="divider"></li>
                    <li><%= link_to 'DROP 2', drop_path %></li>
                </ul>
            </li>
            <li class="divider"></li>
        </ul>
    </section>
</nav>

#4


0  

Using the above example, I make a few tweaks. The above centers everything. The adjustments below centers the topbar, left justifies the text on drop-downs and centers the "hamburger" / menu-icon when in mobile:

使用上面的例子,我做了一些调整。以上是一切。下面的调整将中心放在顶部栏中,左侧将文本放在下拉列表中,并在移动设备中将“汉堡包”/菜单图标置于中心位置:

/* center topbar */
/* set alignment to center for small screens */
nav.top-bar { text-align:center; }
nav.top-bar:not(.expanded) {
        text-align: center;
        section.top-bar-section { 
            /* align drop down menu text to left on large screens */
            text-align:left; 
            display: inline-block;

         }


}
/* center the mobile hamburger menu */
.top-bar .toggle-topbar.menu-icon {
 padding: 0;
 right: 50%;
 margin-right: -36px;
}