CSS Tutorial - How to create template
In this tutorial you will create a CSS template from scratch. You are going to learn how create a fluid CSS layout with 3 columns. The result of this tutorial will be a nice and simple CSS template. It uses only one image in the header so that you are fully free to change colors, fonts or everything else on it. The resulting template is a valid XHTML, includes SEO coding (navigation after content in the code) and tested with 5 browsers (Firefox, Internet Explorer (6-8), Opera, Safari and Chrome). For this tutorial I assume that you have some HTML knowledge.
Use any HTML / CSS editor of your choice for this template. I strongly recommend NOT to copy the code snippets from this tutorial and paste them in your source, but reading, understanding and writing it yourself. If you would like to learn you have to use your fingers to type and not your mouse to copy.
Start with simple HTML mark-up like shown below
<!DOCTYPE html>
<html>
<head>
<title>Layout 1</title>
</head>
<body>
<div id="header">
 Header
</div>
<div id="content">
 Content
</div>
<div id="navigation">
 Navigation
</div>
<div id="news">
 News
</div>
<div id="footer">
 Footer
</div>
</body>
</html>HTML tag div does not have any formatting on its own; you will not see any changes in the browser at this point. But still it is the most important step before you begin with CSS. You have to double check if you divs are opened and closed properly. If not, the whole layout will fail.
Add HTML tag style into the head section of the HTML document.
<head>
<title>Layout 1</title>
<style type="text/css">
...
</style>
</head>* {
 margin:0;
 padding: 0;
}body {
 background: #eeeeee;
 font-family: sans-serif;
 font-size: 12px;
}div#header {
 height: 160px;
 background: #800000;
}Start to centre the content div first. In CSS there is no command “center” for containers. The trick you have to do, is to create a new div (wrapper) around the content div, give it the width of 100% and then add margin to the inner div (content). Change HTML mark-up as shown below:
<div id="wrapper">
<div id="content">
 Content
</div>
</div>div#wrapper {
 width: 100%;
}
div#content {
 margin: 0 25%;
 background: #BDBD00;
}Start to format navigation part. Fill the background with white colour, set the width of the navigation to 25%. Add left float to shift the navigation to the right on the current line. The left float causes the news part to be positioned exactly under the content
div#navigation {
 background: white;
 width: 25%;
 float: left;
}div#wrapper {
 ...
 float: left;
}
div#navigation {
 ...
 margin-left: -100%;
}div#news {
 background: white;
 width: 25%;
 float: left;
 margin-left: -25%;
}div#footer {
 background: #800000;
 width: 100%;
 clear: left;
}<div id="header">
 <h1>business©ompany</h1>
</div>div#header h1 {
 color: white;
 font-size: 86px;
 font-family: serif;
 text-align: right;
 border-bottom: 1px solid #ffffff;
 padding-right: 20px;  
 background: #800000 url(bg.jpg) repeat-x left 25px;  
}Enclose copyright sign in the heading in HTML tag span. This way you can make the sign larger than the rest of the title. To narrow the space before and after the sign reduce normal letter spacing
div#header h1 span {
 font-size: 120%;
 letter-spacing: -5px;
}<div id="header">
 <h1>business<span>©</span>ompany</h1>
</div><div id="wrapper">
 <div id="content">
 <div class="inner">
 Content
 </div>
 </div>
</div>
<div id="navigation">
 <div class="inner">
 Navigation
 </div>
</div>
<div id="news">
 <div class="inner">
 News
 </div>
</div>
<div id="footer">
 <div class="inner">
 Footer
 </div>
</div>div.inner {
 padding: 20px;
}h2 {
 padding: 10px;
 margin-bottom: 10px;
 color: white;
 background: olive;
 font-family: serif;
}
div#navigation ul {
 margin-left: 15px;
}The last step will be formatting the footer part. Add a border to the top of the footer part, text colour and position of text. Format the link colour as well:
div#footer {
 ...
 border-top: 1px solid #eeeeee;
 color: white;
 text-align: right  
}
div#footer a {
 color: white;
}
 

 
No comments:
Post a Comment