use built in components of Bootstrap including glyphs, alerts, panels and modals
create a nav bar in bootstrap
Bootstrap Components
Bootstrap has a variety of built in components that allow for better page design and user interface design. The more common components are glyphs, alerts, panels, modals and navigation bars. This page will discuss the common elements. Other available components include: button groups, bread crumbs, jumbotron, progress bars and more. For the full list, click here.
Glyphs
Bootstrap has a number of built in icons that can be used when creating web pages. These include home, save, edit, arrows, stars, comments, etc. They are part licensed through the Glyphicons Halfling set. These icons allow designers to quickly and efficiently represent information graphically for their users. The glyphs are typically set using a span and the required glyph class.
The above code produces the following icon: The full list of available glyphs can be found here.
Alerts
Alerts are an easy way to draw attention to specific content that you want users to see. Alerts use the basic contextual colors, except for the default, as it does not stand out enough. An alert can be made simply in a div by specifying the alert class along with the contextual alert class. In addition, you must assign the role of the div to be an alert which helps with the styling. Bootstrap should automatically add rounded borders, but if not, apply the appropriate style to the element.
This is your warning. Pay attention.
This is your warning. Pay attention.
With the addition of some extra code, and being sure that the bootstrap javascript is loaded, you can make the alerts dismissable. The extra attributes in the button class are read by both the css and javascript files associated with Bootstrap. Notice the x on the far side of the alert.
Great Job. You saw the warning.
Great Job. You saw the warning.
Panels
Panels allow users to set aside information with headers, footers and main content, if desired. Panels can also be colored using the standard contextual colors. To create a panel with a header and content, use the following code. Note the use of the panel-heading, panel-title and panel-body classes. This help style the panel. In addition, you could add another div below panel body with the class panel-footer to add a footer to the panel. Finally, the width of the panel can be controlled using either columns or the width style.
My Panel Title
This is the panel content.
See me?
My Panel Title
This is the panel content.
See me?
Modals
Modals are dismissible pop-up windows that can display HTML content. A modal, as opposed to the standard JavaScript alert, can hold text, images, tables, bootstrap columns, etc. Modals can also be programmed with buttons of the designers choice that have appropriate actions. At this point, we can make modals appear, but performing actions on button clicks requires some JavaScript programming. It is important that only one modal is open at a time and please note that there are sometimes issues on mobile devices.
The basic parts of a modal are similar to that of a panel. There is a header, body and footer. All of these items are located inside the modal-content holder which, in turn, is located inside the modal-dialog element. See the example below for more information. Also, pay close attendtion to the role=dialog and aria-labelledby="..." in the main div and the role=document in the modal-dialog div. This information is important for the javascript to make the modal appear/disappear. In addition, the aria-labelledby value is the same is the id of the modal-title.
Important Report
Things to Do
Thing 1
thing 2
Thing 3
To make the modal appear, we must create a button. The button code requires two attributes: data-toggle=modal and data-target-"...", where the data-target value is the id of the main div that applies the modal class.
Important Report
Things to Do
Thing 1
thing 2
Thing 3
Navigation
Bootstrap also provides a way for developers to create nav bars. This is important as building a responsive navigation system is not easy, but BS helps out in this area. To start, we must make a nav element with class=navbar. If you choose not to use the nav element as the main element, you must add role=navigation to the navbar parent element. In addition, the navbar can be styled using navbar-defalt (dark on light) or navbar-inverse (light on dark). Also, the navbar can be fixed to the top or bottom of the page if desired using navbar-fixed-top and navbar-fixed bottom. Here are some examples of navbar declarations.
... //this is a default navbar that will scroll off the page
... //inverted navbar fixed to top of page
Within the nav element, there are several pieces that need to be present:
A div with a container-fluid class which spans the full width of the viewport.
A div serving as the header, class=navbar-header. This typically holds the branding, navbar-brand, as text or an image. The brand has special padding and margins.
An unordered list serving as the items on the nav bar, each in its own li element with an a tag wrapped around the link. Also note that the navbar-nav has an id. This will be important later.
To make the navbar collapsable in smaller displays (responsive), there are several items that we need to add:
Include the JQuery javascript library on the page for the collapsable animations
Wrap the navbar-nav, the ul, in a div with a class to collapse the navbar when necessary.
A button in the navbar header that will toggle on when the nav bar collapses. This button will have three lines on it which can be created using a span class with the icon-bar class. The code refers to a data-target which must be the same as the navbar-collapse id.
Other additions can be made to the nav bar including:
Buttons: To make a button on the nav bar, create a normal button and add the navbar-button class.
Forms: To place inline form elements on a navbar, create a form and add the navbar-form class.
Dropdowns: To make a drop down, we set the nav item li class to dropdown. Then, we add an a tag with a series of attributes that combine the Bootstrap CSS and JavaScript to make the actions. After the a tag, we create a nested ul list with list items that will be the dropdown menu items.