Customizing Twitter Bootstrap can be confusing to those that do not understand CSS, and maybe even to those that do. One of the things I found was while I like the topbar, I didn’t always want it at the top of my page. Sometimes you want a logo at the top with the topbar just below it. Moving the topbar is not something that is explicitly spelled out in the Twitter Bootstrap documentation so I wanted to share with you a simple way to do it.
Lets say you want to do something like this:
The easiest thing to do is simply override the topbar selectors. Because of the nature of cascading stye sheets we do not need to include every element included in the topbar selectors within the bootstrap.css file, just the ones we want to change. In this example I created my own CSS file with just the selectors with the elements I needed to modify. This is preferred to editing the bootstrap.css file directly because it enables you upgrade the bootstrap framework without breaking your customizations in the future. So I created a css file, I called mine style.css, and included the following in style.css file:
.topbar-wrapper {
position: relative;
height: 40px;
margin: 0;
}
.topbar-wrapper .topbar {
position: absolute;
margin: 0;
}
.topbar-wrapper .topbar .topbar-inner {
/* Rounded Top */
-moz-border-radius-topleft:4px;
-moz-border-radius-topright:4px;
-webkit-border-top-left-radius:4px;
-webkit-border-top-right-radius:4px;
border-top-left-radius:4px;
border-top-right-radius:4px;
}
Then to ensure your css overrides the bootstrap css all you have to do is include your css file after the bootstrap css file in the head section of your html.
<link rel="stylesheet" href="css/bootstrap.min.css" type="text/css" /> <link rel="stylesheet" href="css/style.css" type="text/css" />
The last step is body of your html. Just include your logo, and/or div that you want to contain the content you wish to display above the topbar. Like this:
<div class="container"> <a href="/">< img src="images/logo.png" alt="Jeffrey Stone" title="Jeffrey Stone" ></a> <div class="topbar-wrapper" style="z-index: 5;">
That all there is to it. Other customizations to Twitter Bootstrap can be carried out in the same way allowing you to customize Twitter Bootstrap to fit you next project. This code has only been tested with Twitter Bootstrap 1.4.
You can view the live demo.
