Making Nice Looking Websites

Our goal should be to make really nice websites, with simple ways of navigation, that are intuitive and easy to follow. The Bootstrap framework handles the heavy lifting with CSS (and JavaScript) that makes for a nice experience. It is now time to make our web interface shine.

Installing Bootstrap v4

Lets create a bootstrap test area in ~/public_html/IT350/bs4test and retrieve the bootstrap distribution into that directory.

umask 0022
mkdir -p ~/public_html/IT350/bs4test/web/bootstrap
cd ~/public_html/IT350/bs4test/web/bootstrap
wget https://github.com/twbs/bootstrap/releases/download/v4.5.3/bootstrap-4.5.3-dist.zip
unzip bootstrap-4*-dist.zip
rm -f bootstrap-4*-dist.zip

Lets grab the fixed-top-navbar from the Bootstrap webpage, ever wanted to download a website?, wget is a useful tool...

cd ~/public_html/IT350/bs4test
wget --no-clobber --convert-links -p -E -e robots=off -U mozilla http://getbootstrap.com/docs/4.5/examples/navbar-fixed/

If you ran the wget command above , then you can navigate to

http://midn.cs.usna.edu/~mAlpha/IT350/bs4test/getbootstrap.com/docs/4.5/examples/navbar-fixed
and see the template in action!.

What about our directory structure?

It would pay great dividends to be able to access the bootstrap template from any script within our website. To do this lets make some very important assumptions about our design:

  1. /web/bootstrap has all files necessary to use the bootstrap template
  2. All of our running scripts will exists within the first directory level of our site (ex. /home/home.php, /review/something.php, etc.)
Why is this important? It means that our pages will always refer to the web directory as ../web/ and out bootstrap directory is always ../web/bootstrap - this actually makes things very convenient.

Now, lets copy some of those files that we just downloaded during our scraping of the boostrap website (you should still be in the ~/public_html/IT350/bs4test/ directory).

cd ~/public_html/IT350/bs4test/web/bootstrap/boot*dist
mv * ..
cd ..
rmdir boot*dist
cd ~/public_html/IT350/bs4test
mkdir test
cp -vn getbootstrap.com/docs/4.5/examples/navbar-fixed/index.html test/
cp -vn getbootstrap.com/docs/4.5/examples/navbar-fixed/navbar-top-fixed.css web/bootstrap/css/mysite.css
cp -vn getbootstrap.com/docs/4.5/assets/js/vendor/* web/bootstrap/js/
sed -i 's_../../dist/_../web/bootstrap/_g' test/index.html
sed -i 's_../../assets/_../web/bootstrap/_g' test/index.html
sed -i 's_navbar-top-fixed.css_../web/bootstrap/css/mysite.css_g' test/index.html
sed -i 's_/vendor/_/_g' test/index.html
# And I dislike dark NavBars, so...
sed -i 's_dark_light_g' test/index.html
rm -rf getbootstrap.com

What just happened? We just modified the index.html file that was the basis of the navbar template, changing the path to the bootstrap css/javascript to something more convenient to our website. If you go to:

http://midn.cs.usna.edu/~mAlpha/IT350/bs4test/test/
You should now see the template in place.

Time to review how the template did this

Below you can see the source code for the index.html file that we scraped from the boostrap example. Pay specific attention to everything between the <nav> </nav> tags.

<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="description" content=""> <meta name="author" content="Mark Otto, Jacob Thornton, and Bootstrap contributors"> <meta name="generator" content="Jekyll v4.1.1"> <title>Fixed top navbar example · Bootstrap</title> <link rel="canonical" href="https://getbootstrap.com/docs/4.5/examples/navbar-fixed/"> <!-- Bootstrap core CSS --> <link href="../web/bootstrap/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-TX8t27EcRE3e/ihU7zmQxVncDAy5uIKz4rEkgIXeMed4M0jlfIDPvg6uqKI2xXr2" crossorigin="anonymous"> <!-- Favicons --> <link rel="apple-touch-icon" href="http://getbootstrap.com/docs/4.5/assets/img/favicons/apple-touch-icon.png" sizes="180x180"> <link rel="icon" href="http://getbootstrap.com/docs/4.5/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png"> <link rel="icon" href="http://getbootstrap.com/docs/4.5/assets/img/favicons/favicon-16x16.png" sizes="16x16" type="image/png"> <link rel="manifest" href="http://getbootstrap.com/docs/4.5/assets/img/favicons/manifest.json"> <link rel="mask-icon" href="http://getbootstrap.com/docs/4.5/assets/img/favicons/safari-pinned-tab.svg" color="#563d7c"> <link rel="icon" href="http://getbootstrap.com/docs/4.5/assets/img/favicons/favicon.ico"> <meta name="msapplication-config" content="/docs/4.5/assets/img/favicons/browserconfig.xml"> <meta name="theme-color" content="#563d7c"> <style> .bd-placeholder-img { font-size: 1.125rem; text-anchor: middle; -webkit-user-select: none; -moz-user-select: none; -ms-user-select: none; user-select: none; } @media (min-width: 768px) { .bd-placeholder-img-lg { font-size: 3.5rem; } } </style> <!-- Custom styles for this template --> <link href="../web/bootstrap/css/mysite.css" rel="stylesheet"> </head> <body> <nav class="navbar navbar-expand-md navbar-light fixed-top bg-light"> <a class="navbar-brand" href="index.html#">Fixed navbar</a> <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation"> <span class="navbar-toggler-icon"></span> </button> <div class="collapse navbar-collapse" id="navbarCollapse"> <ul class="navbar-nav mr-auto"> <li class="nav-item active"> <a class="nav-link" href="index.html#">Home <span class="sr-only">(current)</span></a> </li> <li class="nav-item"> <a class="nav-link" href="index.html#">Link</a> </li> <li class="nav-item"> <a class="nav-link disabled" href="index.html#" tabindex="-1" aria-disabled="true">Disabled</a> </li> </ul> <form class="form-inline mt-2 mt-md-0"> <input class="form-control mr-sm-2" type="text" placeholder="Search" aria-label="Search"> <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button> </form> </div> </nav> <main role="main" class="container"> <div class="jumbotron"> <h1>Navbar example</h1> <p class="lead">This example is a quick exercise to illustrate how fixed to top navbar works. As you scroll, it will remain fixed to the top of your browser’s viewport.</p> <a class="btn btn-lg btn-primary" href="http://getbootstrap.com/docs/4.5/components/navbar/" role="button">View navbar docs »</a> </div> </main> <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script> <script>window.jQuery || document.write('<script src="../web/bootstrap/js/jquery.slim.min.js"><\/script>')</script><script src="../web/bootstrap/js/bootstrap.bundle.min.js" integrity="sha384-ho+j7jyWK8fNQe+A12Hb8AhRq26LrZ/JpcUGGOn+Y7RsweNrtN/tE3MoK7ZeZDyx" crossorigin="anonymous"></script></body> </html>

From looking at the code, you can see that bootstrap uses standard HTML tags within <div> tags to build the navbars.

Bootstrap - A CSS framework for responsive websites

Now that we have seen the power of CSS and JavaScript, lets focus our efforts on the most popular framework used on the internet, Bootstrap. We will be focusing on version 3 and 4 of the framework. Their website is easily readible, I suggest you review the 4.5 documentation.

Basic Layout tools

One of the nice things that you get by using the framework, is the ability to cleanly layout your we pages. Bootstrap uses a 12 column grid system to separate content. Lets look at a simple example:

four columns

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nibh tellus, lobortis et tincidunt sed, interdum sagittis ex. Suspendisse maximus luctus felis sit amet sodales. Sed accumsan diam ac tincidunt posuere. Donec commodo risus convallis leo ullamcorper malesuada. Ut rutrum rhoncus diam, tempor porttitor neque lacinia ac. Nulla hendrerit sapien vitae scelerisque elementum. Nullam et est ex. Mauris velit tellus, feugiat non hendrerit eu, tincidunt sed dui. Morbi sit amet ornare odio. Morbi vel nulla vehicula, blandit turpis ac, vulputate massa. Nunc vehicula ex eget nisl semper, cursus lobortis arcu iaculis. Duis dapibus purus a consequat gravida. Nullam quis bibendum tellus. Curabitur ultrices vel nibh vel fringilla.

Duis in dictum est. Aliquam dignissim id ante ut bibendum. Nullam laoreet, mauris non ultrices aliquam, est sem elementum urna, nec aliquet ligula magna id justo. Nam bibendum vehicula neque, non ornare risus maximus ac. Mauris eget ullamcorper risus. Duis ullamcorper lacus sed mattis convallis. Mauris velit urna, commodo ut pulvinar ac, rutrum vitae nisl. Pellentesque quis lacus mauris. Vestibulum dui quam, gravida ut eleifend at, sodales vitae augue. Vestibulum vel placerat velit. In hac habitasse platea dictumst. Integer metus erat, accumsan sit amet ipsum quis, lobortis pretium purus. Morbi quis ante urna. Sed mollis ante non nunc consequat posuere.

two columns

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nibh tellus, lobortis et tincidunt sed, interdum sagittis ex. Suspendisse maximus luctus felis sit amet sodales. Sed accumsan diam ac tincidunt posuere. Donec commodo risus convallis leo ullamcorper malesuada. Ut rutrum rhoncus diam, tempor porttitor neque lacinia ac. Nulla hendrerit sapien vitae scelerisque elementum. Nullam et est ex. Mauris velit tellus, feugiat non hendrerit eu, tincidunt sed dui. Morbi sit amet ornare odio. Morbi vel nulla vehicula, blandit turpis ac, vulputate massa. Nunc vehicula ex eget nisl semper, cursus lobortis arcu iaculis. Duis dapibus purus a consequat gravida. Nullam quis bibendum tellus. Curabitur ultrices vel nibh vel fringilla.

six columns

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent nibh tellus, lobortis et tincidunt sed, interdum sagittis ex. Suspendisse maximus luctus felis sit amet sodales. Sed accumsan diam ac tincidunt posuere. Donec commodo risus convallis leo ullamcorper malesuada. Ut rutrum rhoncus diam, tempor porttitor neque lacinia ac. Nulla hendrerit sapien vitae scelerisque elementum. Nullam et est ex. Mauris velit tellus, feugiat non hendrerit eu, tincidunt sed dui. Morbi sit amet ornare odio. Morbi vel nulla vehicula, blandit turpis ac, vulputate massa. Nunc vehicula ex eget nisl semper, cursus lobortis arcu iaculis. Duis dapibus purus a consequat gravida. Nullam quis bibendum tellus. Curabitur ultrices vel nibh vel fringilla.

Duis in dictum est. Aliquam dignissim id ante ut bibendum. Nullam laoreet, mauris non ultrices aliquam, est sem elementum urna, nec aliquet ligula magna id justo. Nam bibendum vehicula neque, non ornare risus maximus ac. Mauris eget ullamcorper risus. Duis ullamcorper lacus sed mattis convallis. Mauris velit urna, commodo ut pulvinar ac, rutrum vitae nisl. Pellentesque quis lacus mauris. Vestibulum dui quam, gravida ut eleifend at, sodales vitae augue. Vestibulum vel placerat velit. In hac habitasse platea dictumst. Integer metus erat, accumsan sit amet ipsum quis, lobortis pretium purus. Morbi quis ante urna. Sed mollis ante non nunc consequat posuere.

The columns above were created with the following HTML:

<div class="row">
  <div class="col-md-4">
    <b>four columns</b>
    <p>
      Lorem ipsum dolor..
    </p>
    <p>
      Duis in...
    </p>
  </div>
  <div class="col-md-2">
    <b>two columns</b>
    <p>
      Lorem ipsum dolor..
    </p>
  </div>
  <div class="col-md-6">
    <b>six columns</b>
    <p>
      Lorem ipsum dolor..
    </p>
    <p>
      Duis in...
    </p>
  </div>
</div>

Playing with Paragraphs

Lets look at what happens when we align our text.

<p class="text-left">Left aligned text.</p>
<p class="text-center">Center aligned text.</p>
<p class="text-right">Right aligned text.</p>
<p class="text-justify">Justified text.</p>
<p class="text-nowrap">No wrap text.</p>

Left aligned text.

Center aligned text.

Right aligned text.

Justified text.

No wrap text.

Bootstrap in general

Ok, as a reminder you will want to review the Getting Started and Components sections of the bootstrap pages. There is a considerable amount of content that discusses how boostrap is used and implemented with excellent examples. We will walk through some in class, but you will need to take the time to review all of the options.

A Few practice items

If you go to Components documentation mentioned above, you will see lots of capabilities that a framework like Bootstrap can bring to the table.

The first one discussed is an Alert, so lets try that! Edit the index.html that was created for you above, it should be located in the bs4test/test folder

cd ~/public_html/IT350/bs4test/test
Now edit the index.html file with your favorite editor, and add the following lines after the </nav> and before the <role="main" class="container"> tag.

<div class="alert alert-primary" role="alert">
  A simple primary alert—check it out!
</div>
Try moving that code down so it is within the <div class="jumbotron"> tag, notice how it changed.

Where do I read about Navigation Bars?

For bootstrap 4:

Practice Problems

  1. Modify index.html so that the project name is your name, and there is a drop down navbar option with each of your labs within, all linking correctly.
  2. Move index.html to ~/public_html/IT350/bs4test/web/start.php, if you go to start.php now it should just work.
  3. If you are new to bootstrap, now would be a great time to play with tables and forms.
  4. Create a pretty table in Bootstrap. Take a look at the table options.
  5. What do forms look like in bootstrap, try!