Introduction
As the use of HTML5 and CSS3 continuous to sprung up, folks around the world are looking at them impressively to design their web pages with pixel-perfect standards. HTML5 is much more consideration for its semantic and cross-browser compatibility. It uses relevant tags for common elements such as navigation and footer for an added impact. On the other hand, CSS3 is a sophisticated language that comes packed with many features such as jQuery slider, responsive layout and more to make your design stand out.
This tutorial talks about creating a minimal blogging site using HTML5, CSS3, and jQuery. Following the tutorial, you'll be able to create a website that looks simple, implements modern tools and development techniques and makes use of HiFi CMS.
So, without much ado, let's start the process.
The Markup
Since our goal is just to create a minimal blogging website, look at the markup of our blog below. There isn't any significant difference in the listing page and there are no comments included in the page. The articles are stacked. You can also see how we have kept the non-semantic stuff at bay. Only a "div" container is used. The top-most bar and other embellishments will be loaded via JavaScript.
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8" />
- <title>Title</title>
-
- </head>
- <body>
- <div id="container">
- <header role="banner">
- <h1>
- <a href="/">joel sutherland</a>
- </h1>
- </header>
- <nav>
- <ul>
-
- </ul>
- </nav>
- <div id="blog" class="hidden"><-- blog dropdown -->
- </div>
-
- <article>
- <header>
- <h1>
- <a href="">Post Title</a>
- </h1>
- <div class="postmeta">
- <time datetime="">December 31st, 1969</time>
- <a href="y#comments" class="comments">0 Comments</a>
- </div>
- </header>
-
- <aside class="comments" id="comments">
-
- </aside>
-
- </article>
- </div>
-
-
- </body>
- </html>
Preparing the CSS Layout
Here, again the idea of minimalism will remain the same. So, to do this we need to sure not to use unnecessary images and also avoid repeating the code.
So, let's begin preparing our layout.
Site Background
- html
- {
- background: #d0cec9;
- filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#dedcd9', endColorstr='#f7f7f6');
- background: -webkit-gradient(linear, left top, left bottom, color-stop(0, #dedcd9),
- color-stop(0.1, #f7f7f6), color-stop(1.0, #f7f7f6));
- background: -moz-linear-gradient(top, #dedcd9 0px, #f7f7f6 400px, #f7f7f6 100%);
- }
- body
- {
- background: url(../images/noise.png);
- }
The preceding code shows how we have layered only a 24-bit image accompanied by a gradient, box-shadows, and RGBA for our background. Gradient-stops are great to get a desirable background design. It is also helpful to avoid unnecessary divs wrappers.
Drop-down and Blockquotes
Using RGBA, we are able to keep our texture and gradients up and running.
- blockquote
- {
- margin: 0 0 22px 0;
- background: rgba(0,0,0,.05);
- border-left: 4px solid rgba(0,0,0,.1);
- padding: 22px;
-
- }
Top-shadow and Bars
- #shadow
- {
- position: fixed;
- top: -10px;
- left: 0;
- width: 100 % ;
- height: 10px;
- box - shadow: 0px 0px 7px rgba(0, 0, 0, .2); - moz - box - shadow: 0px 0px 7px rgba(0, 0, 0, .4); - webkit - box - shadow: 0px 0px 7px rgba(0, 0, 0, .2);
- z - index: 2;
- }
- #bars
- {
- width: 100 % ;
- height: 42px;
- margin - top: -20px;
- }
- #bars div
- {
- position: relative;
- float: left;
- width: 54px;
- height: 100 % ;
- margin - right: 55px;
- box - shadow: 0px 2px 5px rgba(0, 0, 0, .35); - moz - box - shadow: 0px 2px 5px rgba(0, 0, 0, .35); - webkit - box - shadow: 0px 2px 5px rgba(0, 0, 0, .35);
- }
- #bars div.n
- {
- background: #2e78bc; }
- # bars div.m
- {
- background: #a3be48;
-
- }
- #bars div.c
- {
- background: #9a9a9a; margin: 0;
-
- }
The preceding code shows the use of a div generated by JavaScript located on the top of the browser viewport. We have also applied a box-shadow to create shadow effects at the top of the page. Also, notice the use of bars that are created using JavaScript markups and CSS.
The CSS: Type
It's quite pleasurable to write cascading stylesheets, especially when you are aware of the ins and outs of vertical grids. In the code below, I have used 22px of the grid and applied an accurate styling format to make sure our design fits well. Initially, the process might seem daunting to you, but as soon as you get the hang of it, you'll be amazed to see how easy it was.
One of the best techniques used to create a grid is to simply pick up a background image and then use it for your grid. However, when selecting an image one needs to ensure that it is 1px wider and taller than your grid. Also, except for the bottom pixel, the rest of the image can be left transparent. You can use a style guide
page to preview what you have done so far. For my design, I have applied a grid on everything, ranging from the drop-down, to the comment section and syntax highlighter.
Now, let's create the design.
The Voodoo Approach
- html, body
- {
- text - rendering: optimizeLegibility;
- text - shadow: 0px 0px 1px rgba(255, 255, 255, .1); - webkit -
- }
Look at the code above, the first line will help in improving kerning in Firefox, whereas the second one will enable you to embed a non-visible text-shadow so that effective anti-aliasing can be done across a number of browsers. The last line will help you maintain the web page compatibility with the older versions of WebKit.
The technique is good, but you can never be assured of its longevity. The lines aren't good enough to support IE and it's also hard to predict their incompatibility with other browsers, especially when it comes to updating them.
Font-face
Using this technique, one can easily integrate and use the font of their choice in any location. The technique is good since you are playing around real browsing text. It is also compatible with a range of browsers, including IE6.
For those who wish to use their own fonts, ensure that they have the licensing permits for it. If you don't do it, you might run the risk of providing your fonts file publicly available. Next, you can proceed to use the Font Squirrel @font-face generator. The main idea of this tool is to take the font file as input and output the same with different formats that are needed by CSS to display the font on your website. It makes more sense if you check the "expert" box here and then do the rest of the task.
Once you are done getting your @font-face CSS, you can proceed to use the font you want.
- h1, h2, h3, h4,h5, h6
- {
- font - family: 'BergamoProRegular',
- georgia,
- serif;
- line - height: 22px;
- margin - bottom: 22px;
- }
This strategical use of CSS will make your grid work exactly as you want. It helps you accomplish a perfect balance in your design including the line-height and margin-bottom.
- h1, h1 a
- {
- font - size: 33px;
- color: #333230;
- line-height: 44px;
- }
That's all you need to do to make the correct use of CSS.
The jQuery and HiFi
JavaScript is used quite frequently on the website and when talking about JavaScript it is hard to ignore jQuery. We will use jQuery to create various elements for our website.
Bars and Shadow
To begin with, markup should be added that I would need for the shadow and bars at the top. Also, it's worth noting that I have completely disregarded the use of padding while adding bars. The reason being, it will help you to prevent any kind of haphazard page jumping during CSS loading and executing JavaScript.
- var bars = '<div id="bars"><div class="n"></div><div class="n"></div><div class="m"></div><div class="m"></div><div class="m"></div><div class="c"></div></div>' $('#container').prepend(bars).css({paddingTop: 0}); $('body').prepend('<div id="shadow" />')
Dropdown
I have used a very simple custom binding for creating a dropdown for my blog.
- $('#blog').bind('toggle', function()
- {
- var $blog = $(this);
- if ($blog.is(':visible')) $blog.trigger('hide');
- else $blog.trigger('show')
- })
- .bind('show', function()
- {
- $(this).slideDown('show');
- })
- .bind('hide', function()
- {
- $(this).slideUp('hide');
- });
- $('#blogbutton').removeAttr('href').
- click(function()
- {
- $('#blog').trigger('toggle');
- });
Ajax Search Via HiFi API
This section of the tutorial will be helpful for those who run their website on HiFi CMS. It's a nice platform with an amazing JSON based API and many exciting features to ensure pleasurable user experience. Here is my HiFi query:
- {'type': 'page', 'content': {'like': searchphrase }}
Using the code above, you'll be able to fetch all the pages that contain the search phrase. HiFi also boasts a JavaScript library that is compatible with jQuery and makes it easier to be implemented on the website. Look at the code below to understand better about how searching and the related results should be displayed.
- var searchphrase = $('#searchbox').val(); hifi({'type': 'page', 'content': {'like': searchphrase }}).each(function(page){ $('ul#results').append('<li>' + page.title + '</li>'); });
The preceding code will help you use the API to search for the posts. It's really cool and fun to play with.
Conclusion
And that's all! Hopefully, you enjoyed reading the tutorial and learned ways to use HTML5, CSS3, and jQuery to create a truly modern and simple blogging website.
Author Biography
Jack Calder is a renowned web developer in Markupcloud Ltd, a leading
psd to html service company. Jack also shares specific knowledge of any technological topic on the web.