Learn HTML step-by-step from A to Z or improve your professional skills.  Home HTML and CSS Tutorials Basics of Div Tags

Basics of Div Tags


Create a new HTML file in Macromedia Dreamweaver 8 (Ctrl+N).

image 1

Then create a new CSS file by following the same steps as above, just make sure you select "CSS" instead of "HTML". Then save the two newly created files in the same folder. For example "my website". Save the HTML file as index.html and the CSS file as css.css.

The first thing we want to do, is to set the padding and the margins on the index site to 0. This is done using the CSS file we just created. Open your CSS file.

image 2

On line 3, type the same as I've done.

image 3

Now, go back to your html page and import your stylesheet.

Then switch to code view.

image 4

Inside the body tags, write this:

<div id="main-wrap">
</div>

This will be the main container of the page.

Then, inside the newly created div tag, create another one. Like this:

<div id="main-wrap">
<div id="header"></div>
</div>

image 5

Then, underneath the header div, still inside the main-wrap, write three more divs.

<div id="content"><div>
<div id="navigation"></div>
<div id="footer"></div>

You should also fill the div tags with some placeholder text like this:

image 6

If you return to the design view, you will see four of your div tags. This is because you filled them with text. Empty div tags will be 0px in height if you don't set the height using CSS.

It doesn't really look like a web site yet. But after some work in the CSS sheet we will get closer to a full site.

Open your CSS sheet.

On a new line, type:

#main-wrap{
width: 800px;
margin: auto;
}

This will set the width of the main-wrap div to 800px. The margin property is set to auto. This will center the div tag.

image 7

If you go back to the html page, you can see the changes we made.

It should look like this:

image 8

Go back to your CSS sheet and write this:

#main-wrap{
width: 796px;
margin: auto;
background-color: #CCCCCC;
padding: 2px;
}
#header{
height: 100px;
margin-bottom: 2px;
}
#content{
float: right;
width: 640px;
padding: 5px;
background-color: #FFFFFF;
}
#navigation{
margin-right: 652px;
padding: 5px;
background-color: #FFFFFF;
}
#footer{
clear: both;
margin-top: 2px;
padding: 5px;
background-color: #FFFFFF;
}

Basics of Div Tags

That's how you set up your divs for a site. If you have any questions ask in the forums, we are there to help you!



Author's URL: Stian Bakkane
Learn HTML step-by-step from A to Z or improve your professional skills. More Tutorials: Featured Materials | Fresh Materials | More HTML Tutorials at Markuptutorials.com

Reader's comments
comments danish January 18, 2012 says:
Thank you!!!! =)
Reply
comments SAMEER January 11, 2012 says:
vry nice sir ... thnaxssssssss
Reply
comments James August 01, 2011 says:
No doubt, div tags are playing an important role in SEO as well. www.pixalweb.com
Reply
comments Heba July 25, 2011 says:
Thank u so much, its really the best to begin...
Reply
comments Jitender Kuamr November 18, 2010 says:
You are providing a good way to learn div tag.
Reply
comments chirag July 31, 2010 says:
THE BEST
Reply
comments abhishek July 31, 2010 says:
it was cool.but i need more to learn.can i have a more in detail sir,please send an ebook.my id:abhi2abhi55@gmail.com.
Reply
comments saravana July 20, 2010 says:
i had read to ur tutor.tis s the easy way to learn div tag. i need the many more free div tutorials.
Reply
comments jj June 30, 2010 says:
good
Reply
comments srirang April 10, 2010 says:
thanku very much for this tutorial
Reply
comments Anwarul haque March 31, 2010 says:
Dear sir/mam
i have read your example its very easy way to learn DIV tag
i am very impress of your examples which is step mention here step by step wise

Reply
comments ajit March 19, 2010 says:
best tutorial
Reply
comments ajit February 27, 2010 says:
best
Reply
comments Mahendra February 24, 2010 says:
You are providing a good way to learn div tag. I want to achieve free div tutor.
Reply
Add comments to "Basics of Div Tags"

Captcha