Find the logo.png
file in the img
folder. You may notice that its dimensions are large, 900px wide. In our final design, it will be only 120px wide. Because the pixels will be compressed into a smaller space, this is a relatively easy way to ensure that the image will look good in all devices, including retina displays. Meanwhile, the file size of the image, which has already been optimized for the Web, is only 19 KB.
So, let's put it in place and constrain its width.
index.html
in your editor.<a class="navbar-brand" href="EB9781782164524_3.html">Bootstrappin'</a>
Bootstrappin'
with this image tag, including its alt
and width
attributes.<img src="img/logo.png" alt="Bootstrappin'" width="120">
index.html
and refresh your browser. You should see the logo in place.You may notice that the navbar height has expanded, and that its bottom edge no longer lines up with the bottom edge of the active nav item. This is due to the default padding placed around navbar-brand
. We need to adjust the appropriate padding values. We can do that in a few quick steps.
bootstrap/navbar.less
in your editor..navbar-brand {
..navbar-brand { float: left; padding: @navbar-padding-vertical @navbar-padding-horizontal;
The padding values are what we're after.
_navbar.less
.less
folder, alongside __main.less
and _variables.less
.// padding: @navbar-padding-vertical @navbar-padding-horizontal;
padding: 22px 30px 0 15px;
When compiled, the line that's commented out in this manner will not be compiled to CSS.
_navbar.less
file and save it.__main.less
, find and comment out the import line for Bootstrap's navbar.less
file. Then, add an import for the new _navbar.less
file just after it.// @import "bootstrap/navbar.less"; @import "_navbar.less";
_navbar.less
is added to your project in your compiler, and then compile __main.less
to css/main.css
.Refresh the browser. You should see the bottom edge of your navbar line back up with the bottom edge of the active link. (You should also see some additional padding between the logo and the Home link.)
main.css
in your editor and search for the selector .navbar {
.Since I've minified my CSS output, mine looks like this: .navbar-brand{float:left;padding:22px 30px 0 15px;
.
The powers of LESS continue to impress. Observe what we've done here:
bootstrap/navbar.less
file just as it was in its original state, so that we can revert back to it if needed__main.less
_navbar.less
, so that we can see where we've been modifying rulesIn other words, we can leave ourselves a rich trail of fallback files and helpful comments—all with no code bloat. Nice bonus.