"menu flex box"
Bootstrap 3.0.0 Snippet by evarevirus

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<header>
<h1>Navigation menus using CSS flexbox</h1>
<p>The markup for all examples illustrated below are identical as follow:</p>
<pre><code><nav>
<ul>
<li><a href="#" title="Home">Home</a></li>
<li><a href="#" title="Blog">Blog</a></li>
<li><a href="#" title="Work">Work</a></li>
<li><a href="#" title="Resources">Resources</a></li>
<li><a href="#" title="Meta">Meta</a></li>
</ul>
</nav></code></pre>
<p>The CSS code provided in each of the demo below can be toggled. They are written in the flavour of <a href="http://sass-lang.com/">Sassy CSS</a>.</p>
</header>
<section>
<h2>Scenario 1</h2>
<p>Equal width elements</p>
<nav id="sc1">
<ul>
<li><a href="#" title="Home">Home</a></li>
<li><a href="#" title="Blog">Blog</a></li>
<li><a href="#" title="Work">Work</a></li>
<li><a href="#" title="Resources">Resources</a></li>
<li><a href="#" title="Meta">Meta</a></li>
</ul>
</nav>
<p>This is the equivalent of specifing each element to be an equal fraction of its parent's full width, i.e. each fraction is of identical size and the sum of their widths is equivalent to the parent's full width.</p>
<p>This effect is achieved with the help of <code>flex: 1 1 100%</code> on the flex items, which is a shorthand for:</p>
<pre><code>flex-grow: 1;
flex-shrink: 1;
flex-basis: 100%;</code></pre>
<p>The property tells the browser to grow the items equally until they fill the full width of their flex parent, which is the <code><ul></code> element in this case. The <code>flex-basis</code> of 100% ensures that all items will be the same size and treated equally.</p>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
@import url(https://fonts.googleapis.com/css?family=Montserrat);
* {
box-sizing: border-box;
}
body {
background-color: #eee;
color: #333;
font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
font-size: 1rem;
line-height: 1.5em;
}
header, section {
background-color: #fff;
margin: 0 auto 2rem;
padding: 1rem 2rem 2rem;
width: 80%;
}
h1, h2, h3, h4, h5, h6 {
font-family: Montserrat, Helvetica Neue, Helvetica, Arial, sans-serif;
font-weight: bold;
line-height: 1.2em;
margin-bottom: 1.5rem;
}
h1 {
font-size: 2rem;
text-align: center;
}
h2 {
font-size: 1.25rem;
margin-bottom: .5rem;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
$(function(){
$('.css-toggle')
.next().hide()
.end().click(function(e){
e.preventDefault();
if($(this).data('toggle') == 1) {
$(this).data('toggle', 0).html('Show CSS').next().slideUp();
} else if(!$(this).data('toggle') || $(this).data('toggle') == 0) {
$(this).data('toggle', 1).html('Hide CSS').next().slideDown();
}
});
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: