Tips for using bootstrap
<header class="navbar-default"> <!--or navbar-inverse -->
<div class="container"> <!-- gives centered look -->
<nav role="navigation">
</nav>
</div>
</header>
container/row/col
<!-- Creates 2 columns -->
<div class="container">
<div class="row">
<div class="col-md-6"></div>
<div class="col-md-6"></div>
</div>
</div>
.container
: for a responsive fixed width.container-fluid
: to span the entire width of the viewport<meta name="viewport" content="width=device-width, initial-scale=1">
.navbar .navbar-nav {
display: inline-block;
float: none;
vertical-align: top;
}
.navbar .navbar-collapse {
text-align: center;
}
// container with the following styles:
.container {
width: _px; // fixed height in pixels
padding: _px // add padding
line-height: _px; // need to play around with this number
}
// child of the container:
.container < some_element {
display: inline-block; // really important
line-height: _px; // again, play around with this value
}
center-block
's class:
img-responsive
is used to make the image shrink and grow proportionally to it's container<div>
<img class="img-responsive center-block" />
</div>
<div class="col-sm-4">col 1</div>
<div class="col-sm-8">col 2</div>
<div class="col-sm-4 col-xs-push-8">col 1</div>
<div class="col-sm-8 col-xs-pull-4">col 2</div>
<nav>
element for the navbar parent element!
<div>
, make sure to add
role=navigation
to it!.container-fluid
by default (which is included as <nav class="container-fluid">
.container
if you prefer<a>
tag with an image and is given a .navbar-brand
, to represent your brand<a href="#" class="navbar-brand>
<img src=...>
</a>
.navbar-toggle
: defines the button..collapsed
: also, defines the button.data-toggle="collapse"
: tells JS that this is what controls the collapsing behavior.data-target="#"
: contains the id of the box that contains the hidden components.aria-expanded=false
: defines the initial state of the hidden component (false
: hidden, true
:
visible).<div>
) that wraps navbar menu, navbar buttons,
forms, ..etc (wrapping all navbar components except .navbar-header
).collapse
and .navbar-collapse
data-target
option for the navbar toggle button.<ul>
!
.nav
and .navbar-nav
<ul>
with a class of .dropdown-menu
within
the <li>
. Give this <li>
a class of .dropdown
<a>
element that contains the following classes:
.dropdown-toggle
: responsible for toggling the dropdownaria-haspopup="true"
: indicates that there is a sub menu for this element!aria-expanded="false"
data-toggle="dropdown"
<ul>
that contains the list, which will contain the class of .dropdown-menu
<nav class="navbar navbar-default navbar-fixed-top">
<!-- Navbar Container -->
<div class="container">
<!-- Navbar Header [contains both toggle button and navbar brand] -->
<div class="navbar-header">
<!-- Toggle Button [handles opening navbar components on mobile screens]-->
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#exampleNavComponents" aria-expanded"false">
<i class="glyphicon glyphicon-align-center"></i>
</button>
<!-- Navbar Brand -->
<a href="#" class="navbar-brand">
Bootstrap Navbar
</a>
</div>
<!-- Navbar Collapse [contains navbar components such as navbar menu and forms ] -->
<div class="collapse navbar-collapse" id="exampleNavComponents">
<!-- Navbar Menu -->
<ul class="nav navbar-nav navbar-right">
<li class="active">
<a href="#">Page 1</a>
</li>
<li>
<a href="#">Page 2</a>
</li>
<li>
<a href="#">Page 3</a>
</li>
<!-- Navbar link with a dropdown menu -->
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Dropdown
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a href="#">Action</a></li>
<li><a href="#">Another action</a></li>
<li><a href="#">Something else here</a></li>
<li><a href="#">Separated link</a></li>
<li><a href="#">One more separated link</a></li>
</ul>
</li>
</ul>
<!-- Navbar Form -->
<form action="#" class="navbar-form">
<div class="form-group">
<input type="text" class="form-control" placeholder="Search">
</div>
<button type="submit" class="btn btn-default">Submit</button>
</form>
<!-- Navbar Button -->
<button type="button" class="btn btn-default navbar-btn navbar-right">Sign in</button>
<!-- Navbar Text -->
<p class="navbar-text">Signed in as Mark Otto</p>
</div>
</div>
</nav>