Teach Yourself Bootstrap Part 4 Code Listings

Part 4: Customizing Bootstrap

Sams Teach Yourself Bootstrap in 24 Hours

Hour 21: Customizing Bootstrap and Your Bootstrap Website

Listing 21.1

body {
  background-color: #4C521D; 
body > .container {
  background-color: #fff;
.jumbotron {
  background: #6c702d;
  background: -moz-linear-gradient(top, #6c702d 0%, #dfdfdf 100%); 
  background: -webkit-gradient(linear, left top, left bottom,
    color-stop(0%,#6c702d), color-stop(100%,#dfdfdf)); 
  background: -webkit-linear-gradient(top,
    #6c702d 0%,#dfdfdf 100%); 
  background: -o-linear-gradient(top, #6c702d 0%,#dfdfdf 100%); 
  background: -ms-linear-gradient(top, #6c702d 0%,#dfdfdf 100%);
  background: linear-gradient(to bottom, #6c702d 0%,#dfdfdf 100%);
  filter: progid:DXImageTransform.Microsoft.gradient(
    startColorstr='#6c702d', endColorstr='#dfdfdf',
    GradientType=0 ); 
  color: #000;
.jumbotron h1 {
  color: #D8AA10;
  text-shadow: 4px 4px 4px #000;
.quote {
  background-color: #6C702D;
  color: #ddd;
.carousel-control.left {
  background-image: -webkit-linear-gradient(left,
    rgba(170,140,23,1) 0,rgba(0,0,0,.0001) 100%);
  background-image: -o-linear-gradient(left,rgba(170,140,23,1) 0,
    rgba(0,0,0,.0001) 100%);
  background-image: -webkit-gradient(linear,left top,right top,
  background-image: linear-gradient(to right,rgba(170,140,23,1) 0,
    rgba(0,0,0,.0001) 100%);
  filter: progid:DXImageTransform.Microsoft.gradient(
    startColorstr='#80000000', endColorstr='#00000000',
.carousel-control.right {
  background-image: -webkit-linear-gradient(left,
    rgba(0,0,0,.0001) 0,rgba(170,140,23,1) 100%);
  background-image: -o-linear-gradient(left,rgba(0,0,0,.0001) 0,
    rgba(170,140,23,1) 100%);
  background-image: -webkit-gradient(linear,left top,right top,
  background-image: linear-gradient(to right,rgba(0,0,0,.0001) 0,
    rgba(170,140,23,1) 100%);
  filter: progid:DXImageTransform.Microsoft.gradient(
    startColorstr='#00000000', endColorstr='#80000000',
h1, h2, h3, h4, h5, h6, a, a:link {
  color: #D8AA10;
.panel-default>.panel-heading {
  background-color: rgba(179,196,170,.25);
.btn.btn-info {
  background-color: #d8aa00;
  border-color: #aa8c10;

Hour 22: Making Bootstrap Accessible

Listing 22.1

  <a href="#main" class="sr-only sr-only-focusable">Skip to primary content</a>
  <div class="container" id="main" tabindex="-1">
    <!-- The main page content -->

Listing 22.2

<div class="form-group has-success has-feedback">
  <label class="control-label" for="fullname">Fill in Your Full
  <input type="text" class="form-control" id="fullname"
         aria-describedby="fullnameStatus" placeholder="Full Name">
  <span class="glyphicon glyphicon-ok form-control-feedback"
  <span id="fullnameStatus" class="sr-only">(success)</span>

Hour 23: Using Less and Sass with Bootstrap

Listing 23.1

@yellow: #F0E433;

p.pull-right { 
  color: @yellow;

Listing 23.2

.centered-block {
  margin-right: auto;
  margin-left: auto;

h1 {
  width: 80%;

Listing 23.3

.green-bordered(@borderwidth: 3px) {
  border: solid green @borderwidth; 

p.pull-right {

p.wide-border {

Listing 23.4

@yellow: #F0E433;
@other-yellow: @yellow - #555;

p.pull-right {
  color: @yellow;
  text-shadow: 2px 2px @other-yellow;

Listing 23.5

@gray-base: #000;
@gray-darker: lighten(@gray-base, 13.5%);
@gray-dark: lighten(@gray-base, 20%);
@gray: lighten(@gray-base, 33.5%);
@gray-light: lighten(@gray-base, 46.7%);
@gray-lighter: lighten(@gray-base, 93.5%);

.black {
  color: @gray-base; // @gray-base
.darkest {
  color: @gray-darker; // @gray-darker
.dark {
  color: @gray-dark; // @gray-dark
.gray {
  color: @gray; // @gray
.light {
  color: @gray-light; // @gray-light
.lightest {
  color: @gray-lighter; // @gray-lighter

Listing 23.6

$yellow: #F0E433;

p.pull-right { 
  color: $yellow;

Listing 23.7

@mixin border-radius($radius) {
  -webkit-border-radius: $radius;
  -moz-border-radius: $radius;
  -ms-border-radius: $radius;
  border-radius: $radius;

.box { @include border-radius(10px); }

Listing 23.8

.myImage {
  @include size (400px, 300px)

Listing 23.9

// Sass code
#main p {
  color: #000000;
  width: 98%;
  .highlight {
  	background-color: #f1b161;

// Output CSS
#main p {
  color: #000000;
  width: 98%;
main p .highlight {
  background-color: #f1b161; 

Listing 23.10

.standard {
  font-family: "Source Sans Pro";
  background-color: #e6b29a;
aside {
  @extend .standard();
  border: solid #efefef 1px;

// compiled CSS
.standard, aside {
  font-family: "Source Sans Pro";
  background-color: #e6b29a;
aside {
  border: solid #efefef 1px;

Listing 23.11

// import the file my-bootstrap-styles.less 
@import "my-bootstrap-styles.less"

Listing 23.12

// import the file _my-bootstrap-styles.scss 
@import "my-bootstrap-styles"

Hour 24: Going Further with Bootstrap

Listing 24.1

Theme Name:   My Bootstrap Blog Theme
Theme URI:    http://example.com/my-bootstrap-theme
Author:       my name
Author URI:   my URL
Description:  This is a theme based off the Bootstrap Blog 
Version:      1.0
License:      Attribution-ShareAlike 3.0 Unported
License URI:  http://creativecommons.org/licenses/by-sa/3.0/
Tags:         blue, light, two columns, responsive, bootstrap

Listing 24.2

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width,
    <!-- The above 3 meta tags *must* come first in the head; any
    other head content must come *after* these tags -->
    <meta name="description" content="">
    <meta name="author" content="">
    <link rel="icon" href="../../favicon.ico">

    <title>Blog Template for Bootstrap</title>

    <!-- Bootstrap core CSS -->
    <link href="../../dist/css/bootstrap.min.css" rel="stylesheet">

    <!-- Custom styles for this template -->
    <link href="blog.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don't actually copy these 2
    lines! -->
    <!--[if lt IE 9]><script
    <script src="../../assets/js/ie-emulation-modes-warning.js">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5
    elements and media queries -->
    <!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js">


    <div class="blog-masthead">
      <div class="container">
        <nav class="blog-nav">
          <a class="blog-nav-item active" href="#">Home</a>
          <a class="blog-nav-item" href="#">New features</a>
          <a class="blog-nav-item" href="#">Press</a>
          <a class="blog-nav-item" href="#">New hires</a>
          <a class="blog-nav-item" href="#">About</a>

    <div class="container">

      <div class="blog-header">
        <h1 class="blog-title">The Bootstrap Blog</h1>
        <p class="lead blog-description">The official example
        template of creating a blog with Bootstrap.</p>

      <div class="row">

Listing 24.3

    <footer class="blog-footer">
      <p>Blog template built for <a href="http://getbootstrap.com">
      Bootstrap</a> by <a href="https://twitter.com/mdo">@mdo</a>.
        <a href="#">Back to top</a>

    <!-- Bootstrap core JavaScript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load
    faster -->
<script src="../../dist/js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <script src="../../assets/js/ie10-viewport-bug-workaround.js">

Listing 24.4


function bootstrap_jquery_scripts() {
	// Register the script
	wp_register_script( 'my-script', get_template_directory_uri() .
    '/bootstrap/js/bootstrap.js', array( 'jquery' ) );
	// Enqueue the script:
	wp_enqueue_script( 'my-script' );
add_action( 'wp_enqueue_scripts', 'bootstrap_jquery_scripts' );


Listing 24.5

<?php get_header(); ?>

        <div class="col-sm-8 blog-main">
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

          <div class="blog-post">
            <h2 class="blog-post-title"><?php the_title(); ?></h2>
            <p class="blog-post-meta"><?php the_time('F jS, Y'); ?>
              by <?php the_author_posts_link(); ?></p>

            <?php the_content(); ?>
          </div><!-- /.blog-post -->
<?php endwhile; else: ?>
	<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>

            <ul class="pager">
              <li><a href="#">Previous</a></li>
              <li><a href="#">Next</a></li>

        </div><!-- /.blog-main -->

        <div class="col-sm-3 col-sm-offset-1 blog-sidebar">
          <div class="sidebar-module sidebar-module-inset">
            <p>Etiam porta <em>sem malesuada magna</em> mollis
            euismod. Cras mattis consectetur purus sit amet
            fermentum. Aenean lacinia bibendum nulla sed
          <div class="sidebar-module">
            <ol class="list-unstyled">
              <li><a href="#">March 2014</a></li>
              <li><a href="#">February 2014</a></li>
              <li><a href="#">January 2014</a></li>
              <li><a href="#">December 2013</a></li>
              <li><a href="#">November 2013</a></li>
              <li><a href="#">October 2013</a></li>
              <li><a href="#">September 2013</a></li>
              <li><a href="#">August 2013</a></li>
              <li><a href="#">July 2013</a></li>
              <li><a href="#">June 2013</a></li>
              <li><a href="#">May 2013</a></li>
              <li><a href="#">April 2013</a></li>
          <div class="sidebar-module">
            <ol class="list-unstyled">
              <li><a href="#">GitHub</a></li>
              <li><a href="#">Twitter</a></li>
              <li><a href="#">Facebook</a></li>
        </div><!-- /.blog-sidebar -->

      </div><!-- /.row -->

    </div><!-- /.container -->

<?php get_footer(); ?>