Coding A CSS3
Coding A CSS3
Website Template
February 16th 2010
Web development is an area in which you have to keep up with the latest
technologies and techniques, so that you are at the top of your game. And no
wonder - this is an area which changes with an amazing pace. What is the
standard now will be obsolete in just a couple of years.
But changes do not come from nowhere. The early adopters are already using
what we are going to use day-to-day a few years from now. One of these
technologies is HTML5 - the new version of the fundamental language of the
web.
Today we are making a HTML5 web template, using some of the new features
brought by CSS3 and jQuery, with the scrollTo plug-in. As HTML5 is still a
work in progress, you can optionally download a XHTML version of the
template here.
Step 2 - HTML
It is a good time to note, that HTML5 is still a work in progress. It will remain
so probably till around 2022 (I am absolutely serious about this). However
some parts of the standard are complete, and can be used today.
In this tutorial, we are using a few of the tags introduced with this new version
of HTML:
These are used exactly as you would use normal divs. With the difference
being that these tags organize your page semantically. In other words, you
can present your content in such a way, that the subject matter of your page
can be more easily determined. As a result services, such as search engines,
will bring you more targeted visitors and thus boost your revenue (and theirs
actually).
However, there are some implications in using HTML5 today. One of the
most notable is the IE family of browsers, which does not support these tags
(it can be fixed with a simple JavaScript include file though). This is why you
should base your decision for moving to HTML5 on your site's audience. And
just for this purpose, we are releasing a pure XHTML version of this template
as well.
template.html - Head section
<!DOCTYPE html> <!-- The new doctype -->
<html>
<head>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></scri
pt>
<style type="text/css">
.clear {
zoom: 1;
display: block;
}
</style>
<![endif]-->
</head>
You can notice the new <DOCTYPE> at line one, which tells the browser that
the page is created with the HTML5 standard. It is also much shorter and
easier to remember than older doctypes.
After specifying the encoding of the document and the title, we move on to
including a special JS file that will enable Internet Explorer (any version) to
render HTML5 tags properly. Again, this means that if a visitor is using IE and
has JavaScript disabled, the page is going to show all messed up. This is
why, depending on your audience, you should consider the regular XHTML
version of this template, which works in any browser and is released free for
all of our readers here.
template.html - Body Section
<body>
<section id="page"> <!-- Defining the #page section with the section tag --
>
<header> <!-- Defining the header section of the page with the appropriate
tag -->
<h1>Your Logo</h1>
<nav class="clear"> <!-- The nav link semantically marks your main site
navigation -->
<ul>
<li><a href="#article1">Photoshoot</a></li>
<li><a href="#article2">Sweet Tabs</a></li>
<li><a href="#article3">Navigation Menu</a></li>
</ul>
</nav>
</header>
Here we use the new section tags, which divide your page into separate
semantic sections. Outermost is the #page section which is set to a width
of 960px in the style sheet (a fairly standard width with older computer
displays in mind). After this comes the header tag and the navigation tag.
Notice the href attributes of the links - the part after the hash
symbol # corresponds to the ID of the article we want to scroll to.
template.html - Article
<!-- Article 1 start -->
<h2>Photoshoot Effect</h2>
<div class="line"></div>
<figure> <!-- The figure tag marks data (usually an image) that is
part of the article -->
<a href="https://tutorialzine.com/2010/02/photo-shoot-css-jquer
y/">
<img src="https://tutorialzine.com/img/featured/641.jpg" wi
dth="620" height="340" /></a>
</figure>
<p>In this tutorial, we are creating a photo shoot effect with our
just-released PhotoShoot jQuery plug-in. With it you can convert a regular div
on the page into a photo shooting stage simulating a camera-like feel.</p>
</div>
</article>
<div class="line"></div>
</footer>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.j
s"></script>
<script src="jquery.scrollTo-1.4.2/jquery.scrollTo-min.js"></script>
<script src="script.js"></script>
</body>
</html>
Lastly, we have the footer tag, which does exactly what you expect it to do. At
the bottom of the page are the rest of the JavaScript includes, which add
the jQuery library and the scrollTo plug-in, which we are going to use in the
next steps.
Step 3 - CSS
As we are using HTML5, we have to take some extra measures with the
styling. The tags that this new version of HTML introduces, are not yet
provided with a default styling. This is however easily fixed with a couple of
lines of CSS code and the page works and looks as it is supposed to:
styles.css - Part 1
header,footer,
article,section,
hgroup,nav,
figure{
/* Giving a display value to the HTML5 rendered elements: */
display:block;
}
article .line{
/* The dividing line inside of the article is darker: */
background-color:#15242a;
border-bottom-color:#204656;
margin:1.3em 0;
}
footer .line{
margin:2em 0;
}
nav{
background:url(img/gradient_light.jpg) repeat-x 50% 50% #f8f8f8;
padding:0 5px;
position:absolute;
right:0;
top:4em;
nav ul li{
display:inline;
}
nav ul li a,
nav ul li a:visited{
color:#565656;
display:block;
float:left;
font-size:1.25em;
font-weight:bold;
margin:5px 2px;
padding:7px 10px 4px;
text-shadow:0 1px 1px white;
text-transform:uppercase;
}
nav ul li a:hover{
text-decoration:none;
background-color:#f0f0f0;
}
#page{
width:960px;
margin:0 auto;
position:relative;
}
article{
background-color:#213E4A;
margin:3em 0;
padding:20px;
text-shadow:0 2px 0 black;
}
figure{
border:3px solid #142830;
float:right;
height:300px;
margin-left:15px;
overflow:hidden;
width:500px;
}
figure:hover{
-moz-box-shadow:0 0 2px #4D7788;
-webkit-box-shadow:0 0 2px #4D7788;
box-shadow:0 0 2px #4D7788;
}
figure img{
margin-left:-60px;
}
/* Footer styling: */
footer{
margin-bottom:30px;
text-align:center;
font-size:0.825em;
}
footer p{
margin-bottom:-2.5em;
position:relative;
}
footer a:hover{
text-decoration:none;
background-color:#142830;
}
footer a.by{
float:left;
footer a.up{
float:right;
}
In the second part of the code, we apply more detailed styling to the elements.
A width for the page section, a hover property for the figure tag and styles
for the links inside of the footer. There are also a few styles that are not
included here, but you can see them in styles.css.
// If a link has been clicked, scroll the page to the link's hash targe
t:
});
With this our template is complete!
Wrapping it up
In this tutorial, we leveraged the new semantic features provided by HTML5,
to design and code a one-page web template. You can use it for free both
personally and commercially, providing you leave the back link intact.
If you like this tutorial, be sure to check out our twitter stream as well, where
we share the latest and greatest design and development links.