Responsive Website Using BootStrap

Responsive Website Using BootStrap

25 169285
Responsive Website Using BootStrap
Responsive Website Using BootStrap

Responsive Website Using BootStrap

Bootstrap 3 tutorial. If you have not used BootStrap so far, or more than that – have not heard about it – I would recommend you take a closer look to this framework. The fact is that this is really a great choice for those who appreciate the convenience and speed of website development. Today I will tell you about how to create a responsive template using BootStrap 3, which will include elements such as: two navigational menus, slider, promo block, a variety of content blocks, various form elements and footer. One more important moment – in this template, we do not use images, it means that our result is focused on speed.

What does the “Responsiveness” mean?

Responsive Web design is a Web design approach aimed at crafting sites to provide an optimal viewing experience – easy reading and navigation with a minimum of resizing, panning, and scrolling—across a wide range of devices (from mobile phones to desktop computer monitors).

A site designed with Responsive Web design adapts the layout to the viewing environment by using fluid, proportion-based grids, flexible images, CSS3 media queries, an extension of the @media rule.

  • The fluid grid concept calls for page element sizing to be in relative units like percentages, rather than absolute units like pixels or points.
  • Flexible images are also sized in relative units, so as to prevent them from displaying outside their containing element.
  • Media queries allow the page to use different CSS style rules based on characteristics of the device the site is being displayed on, most commonly the width of the browser.

Preview:

template preview

Live Demo

Step 1. HTML

Before you start experimenting with BootStrap framework, let’s prepare a basic html model:

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="author" content="Script Tutorials" />
    <meta name="description" content="Responsive Websites Using BootStrap - demo page">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>Responsive Websites Using BootStrap | Script Tutorials</title>
    <!-- css stylesheets -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/style.css" rel="stylesheet">
</head>
<body>
    <!-- BODY PAGE CONTENT -->
    <!-- add javascripts -->
    <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
</body>
</html>

This is the minimal layout which enables the responsive nature of Twitter Bootstrap. In the header we included all the important meta tags and two CSS files, before the closing body, we added both: jQuery and the minimized bootstrap core. This speeds up the loading of the page. Now we can begin with every element of the page.

Top navigation menu

This menu is in the very top: this is fixed navigation bar. Here is the markup:

  <!-- fixed navigation bar -->
  <div class="navbar navbar-fixed-top navbar-inverse" role="navigation">
    <div class="container">
      <div class="navbar-header">
        <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#b-menu-1">
          <span class="sr-only">Toggle navigation</span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
          <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="#">Bootstrap website</a>
      </div>
      <div class="collapse navbar-collapse" id="b-menu-1">
        <ul class="nav navbar-nav navbar-right">
          <li class="active"><a href="#">Menu 1</a></li>
          <li><a href="#">Menu 2</a></li>
          <li><a href="#">Menu 3</a></li>
          <li class="dropdown">
            <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-user"></span><b class="caret"></b></a>
            <ul class="dropdown-menu">
              <li><a href="#">Option 1</a></li>
              <li><a href="#">Option 2</a></li>
              <li><a href="#">Option 3</a></li>
            </ul>
          </li>
        </ul>
      </div> <!-- /.nav-collapse -->
    </div> <!-- /.container -->
  </div> <!-- /.navbar -->

Generally, it consists of three parts: the hidden button (for mobile device to open the menu), navbar-brand (brand/title) element, and UL-LI-based drop-down menu.

Slider

Right after the top menu, there is the slider: the carousel which turns its items. Its layout is quite familiar:

  <!-- slider -->
  <div id="slider" class="carousel slide" data-ride="carousel">
    <!-- controls -->
    <ol class="carousel-indicators">
      <li data-target="#slider" data-slide-to="0" class="active"></li>
      <li data-target="#slider" data-slide-to="1"></li>
      <li data-target="#slider" data-slide-to="2"></li>
    </ol>
    <div class="carousel-inner">
      <!-- slides -->
      <div class="item active">
        <div class="container">
          <div class="carousel-caption">
            <h1>Lorem ipsum - 1</h1>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sit amet tempus massa. Nam quis purus sit amet augue iaculis dapibus non in nisi.<br />Sed sed volutpat neque. Nulla posuere.</p>
            <p><a class="btn btn-lg btn-default" href="#" role="button">Button 1</a></p>
          </div>
        </div>
      </div>
      <div class="item">
        <div class="container">
          <div class="carousel-caption">
            <h1>Lorem ipsum - 2</h1>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sit amet tempus massa. Nam quis purus sit amet augue iaculis dapibus non in nisi.<br />Sed sed volutpat neque. Nulla posuere.</p>
            <p><a class="btn btn-lg btn-primary" href="#" role="button">Button 2</a></p>
          </div>
        </div>
      </div>
      <div class="item">
        <div class="container">
          <div class="carousel-caption">
            <h1>Lorem ipsum - 3</h1>
            <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sit amet tempus massa. Nam quis purus sit amet augue iaculis dapibus non in nisi.<br />Sed sed volutpat neque. Nulla posuere.</p>
            <p><a class="btn btn-lg btn-warning" href="#" role="button">Button 3</a></p>
          </div>
        </div>
      </div>
    </div>
    <!-- left-right controls -->
    <a class="left carousel-control" href="#slider" data-slide="prev"><span class="glyphicon glyphicon-chevron-left"></span></a>
    <a class="right carousel-control" href="#slider" data-slide="next"><span class="glyphicon glyphicon-chevron-right"></span></a>
  </div><!-- /.carousel -->

The familiar – this is because it contains quite usual elements: the ability to switch slides (indicators), the buttons back and forth, and the slides themselves.

Modal box

Modal boxes are quite an important part of the user interface, so we’ll create one modal box:

  <!-- modal box -->
  <div class="modal fade" id="my-modal-box" tabindex="-1" role="dialog" aria-labelledby="my-modal-box-l" aria-hidden="true">
    <div class="modal-dialog">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <div class="modal-title" id="my-modal-box-l">
            <h3>Share it</h3>
          </div>
        </div><!-- /.modal-header -->
        <div class="modal-body">
          <p>Share it box content</p>
          <!-- You may add AddThis code here -->
        </div><!-- /.modal-body -->
      </div><!-- /.modal-content -->
    </div><!-- /.modal-dialog -->
  </div><!-- /.modal -->

Second navigation menu

Finally we come to the main point – the main container which consists of the second navigation menu, footer and additional content blocks. The second menu is not fixed, this is a similar UL-LI-based menu, but the most right element calls the pre-made modal box:

  <!-- second menu bar -->
  <nav class="navbar navbar-default navbar-static">
    <div class="navbar-header">
        <button class="navbar-toggle" type="button" data-toggle="collapse" data-target="#b-menu-2">
            <span class="sr-only">Toggle navigation</span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
            <span class="icon-bar"></span>
        </button>
        <a class="navbar-brand" href="https://script-tutorials.com/responsive-website-using-bootstrap/">Bootstrap website</a>
    </div>
    <!-- submenu elements for #b-menu-2 -->
    <div class="collapse navbar-collapse" id="b-menu-2">
      <ul class="nav navbar-nav">
        <li class="active"><a href="#"><span class="glyphicon glyphicon-home"></span> Home</a></li>
        <li><a href="#"><span class="glyphicon glyphicon-question-sign"></span> Help</a></li>
        <li><a href="#"><span class="glyphicon glyphicon-exclamation-sign"></span> About</a></li>
        <li class="dropdown">
          <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="glyphicon glyphicon-list"></span> Other <b class="caret"></b></a>
          <ul class="dropdown-menu">
            <li><a href="#">Submenu 1</a></li>
            <li><a href="#">Submenu 2</a></li>
            <li><a href="#">Submenu 3</a></li>
            <li><a href="#">Submenu 4</a></li>
            <li class="divider"></li>
            <li><a href="#">Submenu 5</a></li>
            <li><a href="#">Submenu 6</a></li>
            <li class="divider"></li>
            <li><a href="#">Submenu 7</a></li>
          </ul>
        </li>
      </ul>
      <ul class="nav navbar-nav navbar-right">
        <li data-toggle="modal" data-target="#my-modal-box"><a href="#"><span class="glyphicon glyphicon-share"></span> Share popup</a></li>
      </ul>
    </div><!-- /.nav-collapse -->
  </nav>

Two column layout with blocks

This section is quite huge, but it is rather simple: blocks are repeated. Just pay attention to my comments:

  <!-- 2-column layout -->
  <div class="row row-offcanvas row-offcanvas-right">
    <div class="col-xs-12 col-sm-9">
      <!-- jumbotron -->
      <div class="jumbotron">
        <h1>Lorem ipsum</h1>
        <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sit amet tempus massa. Nam quis purus sit amet augue iaculis dapibus non in nisi. Sed sed volutpat neque. Nulla posuere.</p>
        <p><a role="button" href="#" class="btn btn-lg btn-success">Sign up today</a></p>
      </div>
      <div class="row">
        <!-- column 1 -->
        <div class="col-sm-6">
          <!-- box 1 -->
          <div class="panel panel-default">
            <div class="panel-heading">
              <h3 class="panel-title">Panel 1 title</h3>
            </div>
            <div class="panel-body">
              <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sit amet tempus massa. Nam quis purus sit amet augue iaculis dapibus non in nisi. Sed sed volutpat neque. Nulla posuere.</p>
              <p><a class="btn btn-default right" href="#" role="button">Continue &raquo;</a></p>
            </div>
          </div>
          <!-- box 2 -->
          <div class="panel panel-primary">
            <div class="panel-heading">
              <h3 class="panel-title">Panel 2 title</h3>
            </div>
            <div class="panel-body">
              <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sit amet tempus massa. Nam quis purus sit amet augue iaculis dapibus non in nisi. Sed sed volutpat neque. Nulla posuere.</p>
              <p><a class="btn btn-default right" href="#" role="button">Continue &raquo;</a></p>
            </div>
          </div>
        </div> <!-- /column 1 -->
        <!-- column 2 -->
        <div class="col-sm-6">
          <!-- box 3 -->
          <div class="panel panel-success">
            <div class="panel-heading">
              <h3 class="panel-title">Panel 3 title</h3>
            </div>
            <div class="panel-body">
              <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sit amet tempus massa. Nam quis purus sit amet augue iaculis dapibus non in nisi. Sed sed volutpat neque. Nulla posuere.</p>
              <p><a class="btn btn-default right" href="#" role="button">Continue &raquo;</a></p>
            </div>
          </div>
          <!-- box 4 -->
          <div class="panel panel-warning">
            <div class="panel-heading">
              <h3 class="panel-title">Panel 4 title</h3>
            </div>
            <div class="panel-body">
              <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sit amet tempus massa. Nam quis purus sit amet augue iaculis dapibus non in nisi. Sed sed volutpat neque. Nulla posuere.</p>
              <p><a class="btn btn-default right" href="#" role="button">Continue &raquo;</a></p>
            </div>
          </div>
        </div> <!-- /column 2 -->
      </div><!--/row-->
    </div><!--/span-->
    <!-- column 3 (sidebar) -->
    <div class="col-sm-3 sidebar-offcanvas" id="sidebar">
      <div class="list-group" role="navigation">
        <a href="#" class="list-group-item">Link</a>
        <a href="#" class="list-group-item">Link</a>
        <a href="#" class="list-group-item active">Link</a>
        <a href="#" class="list-group-item">Link</a>
        <a href="#" class="list-group-item">Link</a>
      </div>
      <!-- box 5 -->
      <div class="panel panel-danger">
        <div class="panel-heading">
          <h3 class="panel-title">Form elements</h3>
        </div>
        <div class="panel-body">
          <form role="form">
            <div class="form-group">
              <label for="emailField">Email address</label>
              <input type="email" class="form-control" id="emailField" placeholder="Enter email">
            </div>
            <div class="form-group">
              <label for="selectField">Type</label>
              <select class="form-control" id="selectField">
                <option>1</option>
                <option>2</option>
                <option>3</option>
                <option>4</option>
                <option>5</option>
              </select>
            </div>
            <div class="progress progress-striped active">
              <div class="progress-bar progress-bar-success" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:30%">
                <span class="sr-only">30% Complete</span></div>
            </div>
            <button type="submit" class="btn btn-default">Submit</button>
          </form>
        </div>
      </div>
      <!-- box 6 -->
      <div class="panel panel-info">
        <div class="panel-heading">
          <h3 class="panel-title">Panel 6 title</h3>
        </div>
        <div class="panel-body">
          <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sit amet tempus massa. Nam quis purus sit amet augue iaculis dapibus non in nisi. Sed sed volutpat neque. Nulla posuere.</p>
          <p><a class="btn btn-default right" href="#" role="button">Continue &raquo;</a></p>
        </div>
      </div>
    </div><!-- /column 3 (sidebar) -->
  </div><!--/row-->

In the beginning, the whole layout is divided into two columns, but then, the first column is split to another two columns. In the first column, there is the ‘jumbotron’ element, which you can use to put some introduction in there. As I remarked before – all blocks are very similar, here is the markup of the basic block:

  <div class="panel panel-default">
    <div class="panel-heading">
      <h3 class="panel-title">Panel 1 title</h3>
    </div>
    <div class="panel-body">
      <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. In sit amet tempus massa. Nam quis purus sit amet augue iaculis dapibus non in nisi. Sed sed volutpat neque. Nulla posuere.</p>
      <p><a class="btn btn-default right" href="#" role="button">Continue &raquo;</a></p>
    </div>
  </div>

In order to change it’s color, you may change its class (panel-default) to one of the following: panel-primary, panel-success, panel-info, panel-warning or panel-danger.

Footer

There is only one unexplained element – footer

  <footer>
    <nav class="navbar navbar-default navbar-static-bottom" role="navigation">
    <p class="navbar-text">&copy Copyright 2013</p>
    <p class="navbar-text navbar-right"><a href="https://script-tutorials.com/">Script Tutorials</a></p>
    </nav>
  </footer>

Step 2. CSS

By and large – all the things that we’ve created – does not require special styles. Most of possible elements are already defined in BootStrap stylesheet file (bootstrap.min.css). However, there is only one customized element – the slider (carousel):

css/style.css

.carousel {
    height: 300px;
    margin-bottom: 50px;
}
.carousel-caption {
    z-index: 10;
}
.carousel .item {
    background-color: rgba(0, 0, 0, 0.8);
    height: 300px;
}

Live Demo

[sociallocker]

download in package

[/sociallocker]


Conclusion

In the process of learning the BootStrap framework, we have come to an end. Basically, we only prepared the necessary layout of the page, all the rest has done by this framework. Wonderful, is not it? Thank you for reading this tutorial. Don’t hesitate to share it with your friends using the form below.


25 COMMENTS

  1. Nice summary. Especially like that the examples, concise and to the point … No ‘Magic’ … other than Bootstrap :) This doc covers most of the commonly used styles and desired behaviors. Good work Andrew !

    • Hi Dmitry,
      Yes, I don’t mind about it. At present I study WordPress, and later I will sometimes write articles and for this system.

  2. Hi

    Thanks for your reply.. your reply was not clearly

    This links are your local folder link.. its not have an http links… send me your

    three link files..

  3. Hi
    Great tutorial with many options, and even more to bee added by following the standard Bootstrap tutorials elswhere.
    I have been playing a little around and find some strange acting using newest Bootstrap v3.2.0 instead of the Bootstrap v3.0.2 you use.
    Problem is only on mobile (small browser window) and has to do with right side ‘list-group’ with huge amount of white space.
    Is there a simple workaround to fix this?

  4. Hello, can you please share the markup for the basic block containing the jumbotron. Because on small screen the jumbotron and the 5 panels are not displayed.

    Thank you.

    • Hi John, the code is pretty easy:
      <div class="jumbotron">
      <h1>Lorem ipsum</h1>
      <p>some dummy text</p>
      </div>

  5. ? like it so much want to use it but;
    it doesnt work for me =) i coppyed even exapmle page on my desktop then on clik and black screen .. How ?

    • Hello Mehmet, try to use our package, it works if you run it on localhost (in case if you need to work on local computer)

  6. Hey i really love this menu. But i have a question. is it intended that the nav_current.png pic isnt moving when u “visit” the other pseudo links? should it be static the way it is? if not … it aint moving for me neither on my site and in the demo.

    • Hi, most links of this demo are blank links (#), because this is demo. You always may replace all these links with desired links

  7. Hi
    Could you possibly help me with the second menu (the sticky part)
    I am trying to build a website for Inhambane tourism Association (non profit) and would love to incorporate it
    I am using “Bootstrap General Theme 4” as a basis
    Kind Regards
    Larry

    • Hi Larry, do you need to have two sticky menus on page? Or only one? In this tutorial, only the first menu is sticky on top, the additional second menu is not sticky.

Leave a Reply to Andrey Cancel reply