Reputation: 4617
Hello guys i am using foundation framework to build a fixed navigation
My html is as follows
<div class="fixed">
<div class="contain-to-grid">
<nav class="top-bar">
<ul class="title-area">
<li class="name hide-for-medium-up"><h1><a href="#">topbar</a></h1></li>
<li class="toggle-topbar menu-icon"><a href="#"><span>Menu</span></a></li>
</ul>
<div class="top-bar-section">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">about</a></li>
<li><a href="#">services</a></li>
</ul>
</div>
</nav>
</div>
</div>
My question is:- i need to remove the title area for large devices and need to center the top-bar-section horizontally i removed h1 tag by adding hide-for-medium-up class but i couldnt center the tap-bar-section. It is possible to align this section to left or to right by applying left or right classes to top-bar-sections's ul tag. But i didnt find a way to center it i used following sass rules. But it didnt work
.top-bar-section {
text-align: center;
margin: 0 auto;
ul {
li {
a {
font-size: emCalc(14px);
font-weight: 400;
}
}
}
}
Upvotes: 1
Views: 1760
Reputation: 4404
Here is the best solution I've found that works for all resize events. It centers the Foundation 5 Top-bar elements.
Do note the 'contain-to-grid' div class will keep the widths of the top-bar nav within the frameworks of the website yet will not actually center the nav elements.
The code below does.
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 'Dropping', "#" %>
<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>
</ul>
</section>
</nav>
</div>
Upvotes: 0
Reputation: 23873
You need some media queries to make this happen.
Foundation does not provide any facilities for easy media query manipulation, so i suggest using Breakpoint Slicer.
@import "foundation";
@import "breakpoint-slicer";
// For large devices only
@include from(4) {
// Removing the title area for large devices
.title-area {
display: none;
}
// Centering the menu
.top-bar-section {
text-align: center;
margin: 0 auto;
ul {
li {
display: inline-block;
a {
font-size: emCalc(14px);
font-weight: 400;
}
}
}
}
}
Also note the li { display: inline-block; }
.
Demo: http://sassbin.com/gist/5780699/ (play with the width of the rendered page panel).
Upvotes: 1