What We’ll Cover
- Hero Section
- Navigation
- Title
- Pagination
Why don’t we add a small hero section on top of the index page? I want something that gives us an opportunity to brand the podcast site without going full-splashy-marketing-page-nuts. I strongly trust in “less is more” and moreover, in “don’t insult your users by bombarding them with nonsense”. Let’s keep it nice and simple.
In this last article we will make use of another part of the Bourbon family and implement a couple of patterns from Refills—which provides a pattern / components library (styled and unstyled) and is built with Bourbon and Neat. Why reinvent the wheel when we can now and then adjust existing ones to our needs?
Note: The Refills project is maintained by designers at thoughtbot—so it’s in very good hands quality-wise.
Go to http://refills.bourbon.io/ and copy the markup for the “Hero Unit”. The provided markup is placed in our index file—right above the part where we iterate over our page_articles. In “source/index.html.erb”:
- ...
- <div class="hero">
- <div class="hero-inner">
- <a href="" class="hero-logo"><img src="https://raw.githubusercontent.com/thoughtbot/refills/master/source/images/placeholder_logo_1.png
- " alt="Logo Image"></a>
- <div class="hero-copy">
- <h1>Short description of Product</h1>
- <p>A few reasons why this product is worth using, who it's for and why they need it.</p>
- </div>
- </div>
- </div>
- <div class='posts'>
- <% page_articles.each_with_index do |article, i| %>
- <h2 class='post-title'><span class='post-date'><%= article.date.strftime('%b %e') %></span> <%= link_to article.title, article %></h2>
- ...
Here I copied the styles from Refills’ pattern section as well, placing them into a new file dedicated to this banner section. The provided styles are in the .scss syntax and so I go with the flow—there’s no need to convert this into .sass really.
In “source/stylesheets/_hero_banner.scss”:
- .hero {
- $base-border-radius: 3px !default;
- $action-color: #477DCA !default;
- $large-screen: em(860) !default;
- $hero-background-top: #7F99BE;
- $hero-background-bottom: #20392B;
- $hero-color: white;
- $gradient-angle: 10deg;
- $hero-image: 'https://raw.githubusercontent.com/thoughtbot/refills/master/source/images/mountains.png';
- @include background(url($hero-image), linear-gradient($gradient-angle, $hero-background-bottom, $hero-background-top), no-repeat $hero-background-top scroll);
- background-color: #324766;
- background-position: top;
- background-repeat: no-repeat;
- background-size: cover;
- padding-bottom: 3em;
- .hero-logo img {
- height: 4em;
- margin-bottom: 1em;
- }
- .hero-inner {
- @include outer-container;
- @include clearfix;
- margin: auto;
- padding: 3.5em;
- text-align: center;
- .hero-copy {
- text-align: center;
- h1 {
- color: $hero-color;
- font-size: 1.6em;
- margin-bottom: 0.5em;
- @include media($large-screen) {
- font-size: 1.8em;
- }
- }
- p {
- color: $hero-color;
- line-height: 1.4em;
- margin: 0 auto 3em auto;
- @include media($large-screen) {
- font-size: 1.1em;
- max-width: 40%;
- }
- }
- }
- }
- }
![]() |
Ignore the typography for now, you can adjust it later. I replaced the image and put a slight gradient on top of it. Since the type is white, I needed a bit more contrast for a better reading experience. If you choose an image that does not need an additional gradient, go for it!
I adjusted the Refills code with a couple of changes. First, I added an image to “source/images” and saved this image in the variable $hero-image. Then I reused this variable in the background mixin from Bourbon and reordered the image and the linear-gradient (a Bourbon mixin as well). Because the gradient comes first, it is overlayed on top of the Matcha_Nerdz.png. Once more, in “source/stylesheets/_hero_banner.scss”:
- .hero {
- $hero-image: '../images/Matcha_Nerdz.png';
- $hero-background-top: darken($matcha-green, 65%);
- $hero-background-bottom: rgba(lighten($matcha-green, 10%), .3);
- @include background(linear-gradient($gradient-angle, $hero-background-bottom, $hero-background-top), url($hero-image), no-repeat $hero-background-top scroll);
- margin-bottom: 2em;
- //background-color: #324766;
- //background-size: cover;
For the gradient itself, I reused our $matcha-green that we stored in “source/stylesheets/base/_variables.scss”. The top color is darkend by 65% with a Sass function; the other one is lightened by 10% and also made transparent via another Sass function called rgba. We then reuse these variables in our background mixin. The gradient-angle stayed the same. I also added a small margin of 2em to push the index list down a bit. The styles I commented out for you are dead weight and so I deleted them.
You can play with such a gradient directly in Photoshop as well, of course, but I wanted to show you how you can use them in Sass. Below is a screenshot that has no linear gradient added to the hero unit. As a little exercise, I’ll leave the cleanup of the styles we copied to you. If you find duplicates or unused styles, I recommend you fix this before moving on.
![]() |
Commit and Deploy
Time for another commit and deploy.
- git add --all
- git commit -m 'Adds hero unit to index.html.erb
- Adds hero image with gradient
- Adds _hero_banner Sass partial
- Imports Sass partial'
- middleman deploy
![]() |
Without the visual grid, it doesn’t look you have much work left to adjust this page for your podcasting needs. A few things I’d recommend you do is find a typeface that communicates your project distinctively without being too exotic and adjust the size and spacing of your text so that it fits your hero unit background image. Since this is part of your branding, I suggest you take your time and have some fun!
Navigation
It’s a good time to add a navbar. Again, we will use an existing pattern from Refills and adapt it for our own needs. I chose the “Centered Navigation” which you will find under “Patterns”. For this one, we need to copy the HTML, SCSS and the CoffeeScript code. I’ll start first by adding the markup to our global “layout.erb” file
- <!doctype html>
- <html>
- <head>
- <meta charset="utf-8" />
- <meta http-equiv='X-UA-Compatible' content='IE=edge;chrome=1' />
- <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
- <title>Blog Title<%= ' - ' + current_article.title unless current_article.nil? %></title>
- <%= feed_tag :atom, "#{blog.options.prefix.to_s}/feed.xml", title: "Atom Feed" %>
- <%= stylesheet_link_tag "all" %>
- <%= javascript_include_tag "all" %>
- </head>
- <body>
- <header class="centered-navigation" role="banner">
- <div class="centered-navigation-wrapper">
- <a href="javascript:void(0)" class="mobile-logo">
- <img src="https://raw.githubusercontent.com/thoughtbot/refills/master/
- source/images/placeholder_logo_3_dark.png" alt="Logo image">
- </a>
- <a href="javascript:void(0)" id="js-centered-navigation-mobile-menu" class="centered-navigation-mobile-menu">MENU</a>
- <nav role="navigation">
- <ul id="js-centered-navigation-menu" class="centered-navigation-menu show">
- <li class="nav-link"><a href="javascript:void(0)">Products</a></li>
- <li class="nav-link"><a href="javascript:void(0)">About Us</a></li>
- <li class="nav-link"><a href="javascript:void(0)">Contact</a></li>
- <li class="nav-link logo">
- <a href="javascript:void(0)" class="logo">
- <img src="https://raw.githubusercontent.com/thoughtbot/refills/master/
- source/images/placeholder_logo_3_dark.png" alt="Logo image">
- </a>
- </li>
- <li class="nav-link"><a href="javascript:void(0)">Testimonials</a></li>
- <li class="nav-link more"><a href="javascript:void(0)">More</a>
- <ul class="submenu">
- <li><a href="javascript:void(0)">Submenu Item</a></li>
- <li><a href="javascript:void(0)">Another Item</a></li>
- <li class="more"><a href="javascript:void(0)">Item with submenu</a>
- <ul class="submenu">
- <li><a href="javascript:void(0)">Sub-submenu Item</a></li>
- <li><a href="javascript:void(0)">Another Item</a></li>
- </ul>
- </li>
- <li class="more"><a href="javascript:void(0)">Another submenu</a>
- <ul class="submenu">
- <li><a href="javascript:void(0)">Sub-submenu</a></li>
- <li><a href="javascript:void(0)">An Item</a></li>
- </ul>
- </li>
- </ul>
- </li>
- <li class="nav-link"><a href="javascript:void(0)">Sign up</a></li>
- </ul>
- </nav>
- </div>
- </header>
- <div id="main" role="main">
- <%= yield %>
- </div>
- <%= partial "partials/footer" %>
- </body>
- </html>
Whoa! That’s quite a chunk of code. Are you thinking the same as me? This looks nasty, right? Let’s put this into a partial. We’ll change “source/layouts/layout.erb” to:
- ...
- <body>
- <%= partial "partials/navbar" %>
- <div id="main" role="main">
- <%= yield %>
- </div>
- <%= partial "partials/footer" %>
- </body>
- </html>
And add “source/partials/_navbar.erb”:
- <header class="centered-navigation" role="banner">
- <div class="centered-navigation-wrapper">
- <a href="javascript:void(0)" class="mobile-logo">
- <%= image_tag "matcha_nerdz_logo.png", alt: "Logo image" %>
- </a>
- <a href="javascript:void(0)" id="js-centered-navigation-mobile-menu" class="centered-navigation-mobile-menu">MENU</a>
- <nav role="navigation">
- <ul id="js-centered-navigation-menu" class="centered-navigation-menu show">
- <li class="nav-link"><%= link_to 'Home', '/matcha-nerdz' %></li>
- <li class="nav-link logo">
- <%= image_tag "matcha_nerdz_logo.png", alt: "Logo image" %>
- </li>
- <li class="nav-link"><%= link_to 'About', '/pages/about.html' %></li>
- </ul>
- </nav>
- </div>
- </header>
I’ve removed a bunch of stuff that I don’t need and only end up with my logo that I stored in “/images” and two links for home and about pages. For the two links I used the link_to helper method. It takes two arguments:
- The string you want users to click on
- and the location you want to link to.
I’m sure people who have played a bit with Rails or Sinatra are familiar with this. Handy, but no big deal. The link for “Home” (/matcha-nerd) will break for your local host but it is working on GitHub Pages where we need the namespace.
The avid reader might also have discovered that our about link links to a simple HTML page that I placed in a new directory named “pages”. I suggest you put HTML pages like contact, faq or whatever also in this directory. If you put these static pages in there you should have no problems customizing them to your needs. Just have some fun and apply what you’ve learned so far with these pages. From here on you are on your own with these, but you now know everything you need. Samo, samo!
Asset Path
A word about the image tags and the asset path on GitHub Pages. I decided to replace the plain img tags for the logo with a Middleman helper called image_tag. It’s not only pretty concise and readable, but also fixes an issue you will run into with the img tag when you build the site and deploy it to GitHub Pages. The url for the asset link on individual articles gets all screwed up and this is the simplest solution to fix that.
- <img src="/images/matcha_nerdz_logo.png" alt="Logo image">
http://your_username.github.io/images/matcha_nerdz_logo-hash_numbers.png
- <%= image_tag "matcha_nerdz_logo.png", alt: "Logo image" %>
This Middleman helper provided the url with the app name matcha-nerdz—it correctly namespaced the asset and gives GitHub Pages access to this image file (http://your_username.github.io/matcha-nerdz/images/matcha_nerdz_logo-hash_numbers.png).
Written by:Ed Wassermann (countinue)
If you feel useful for you and for everyone, please support and follow us.
Suggest for you:



No comments:
Post a Comment