Div Layer Tutorial (Advanced)

HTML Tutorials

Tutorial

Click on thumbnailed images to enlarge

What is a Div Layer?

Div layers are similar to tables with a few more options to be spoken of. A div layer is a section on your website in which you can place any information. What it has that can be much more helpful is the ability to specify the location of the layer.

<div style=\"height:150; width:50;\">This is a Div Layer</div>


As you will see this just creates a section to write the line above in. Since the style has no border you just see text and there's no background color difference.


The next step that can be taken in a div layer is to change the background color. That can be done using the following code.

<div style=\"height:150; width:50; background-color:ff0000;\">This is a Div Layer with a red background</div>



If you don't want background color simply take out that portion of the code. Instead a border can be used to show the edges of the layer.

<div style=\"height:150; width:50; border:1; border-style:solid; border-color:ff0000;\">This is a Div Layer</div>



Here you will notice the border is set to 1 pixel wide and the color of the border is red. Also, notice you need to declare a border style or the border will not appear. Some choices for border style are solid, dashed, or dotted.
In the style section of div which is what we are concentrating on here you may notice that most commands are the same as in any other tag. Therefore padding will work here just as it did in the sections of the table. IF you notice in the previous example the text is right next to the border while in the example below (using padding) we are able to create a space between the text and the border.

The biggest thing to notice about div layers such as these is if you create the size too small the layer will not adjust the size. Text will simply flow out of the border.

Div layers can also have the code overflow:; placed within the style=" " and it can either have hidden or visible as the value of overflow.
Visible displays all text regardless of layer size constraints. Hidden hides it.

Div Positioning

Div positioning is where the whole div layer idea gets a little tougher. There are two types of positioning. Absolute and Relative. Before we get into examples I will do my best to explain the difference.

When using absolute positioning the basis for the distance is the sites borders. Meaning if you position absolutely and say to have it 10 pixels from the top it will be exactly 10 pixels from the top of the page.

When using relative positioning the position is not based on the entire page instead it is based on the bottom of the last thing placed on your site. If a table is written before using a div layer the position is based on the bottom of the table.

Positions can be based on top:;, bottom:;, left:;, or right:;. Try to only use left or right and top or bottom. In between : and ; place the number of pixels you would like the div layer to be from that section.

<div style=\"position:absolute; top:10; left:20; border:1; border-color:black; border-style:dashed;\">This is a div layer with positioning 10 from the top and 20 from the left.</div>


Absolute positioning would result in positioning based on the entire page. Top:0; would move the layer to the top of the page.


<div style=\"position:relative; top:10; right:300; border:1; border-color:black; border-style:dashed;\">This is a div layer with positioning 10 from the top and 300 from the right.</div>
What is a Div Layer?

Div layers are similar to tables with a few more options to be spoken of. A div layer is a section on your website in which you can place any information. What it has that can be much more helpful is the ability to specify the location of the layer.

<div style=\"height:150; width:50;\">This is a Div Layer</div>


As you will see this just creates a section to write the line above in. Since the style has no border you just see text and there's no background color difference.


The next step that can be taken in a div layer is to change the background color. That can be done using the following code.

<div style=\"height:150; width:50; background-color:ff0000;\">This is a Div Layer with a red background</div>



If you don't want background color simply take out that portion of the code. Instead a border can be used to show the edges of the layer.

<div style=\"height:150; width:50; border:1; border-style:solid; border-color:ff0000;\">This is a Div Layer</div>



Here you will notice the border is set to 1 pixel wide and the color of the border is red. Also, notice you need to declare a border style or the border will not appear. Some choices for border style are solid, dashed, or dotted.
In the style section of div which is what we are concentrating on here you may notice that most commands are the same as in any other tag. Therefore padding will work here just as it did in the sections of the table. IF you notice in the previous example the text is right next to the border while in the example below (using padding) we are able to create a space between the text and the border.

The biggest thing to notice about div layers such as these is if you create the size too small the layer will not adjust the size. Text will simply flow out of the border.

Div layers can also have the code overflow:; placed within the style=" " and it can either have hidden or visible as the value of overflow.
Visible displays all text regardless of layer size constraints. Hidden hides it.

Div Positioning

Div positioning is where the whole div layer idea gets a little tougher. There are two types of positioning. Absolute and Relative. Before we get into examples I will do my best to explain the difference.

When using absolute positioning the basis for the distance is the sites borders. Meaning if you position absolutely and say to have it 10 pixels from the top it will be exactly 10 pixels from the top of the page.

When using relative positioning the position is not based on the entire page instead it is based on the bottom of the last thing placed on your site. If a table is written before using a div layer the position is based on the bottom of the table.

Positions can be based on top:;, bottom:;, left:;, or right:;. Try to only use left or right and top or bottom. In between : and ; place the number of pixels you would like the div layer to be from that section.

<div style=\"position:absolute; top:10; left:20; border:1; border-color:black; border-style:dashed;\">This is a div layer with positioning 10 from the top and 20 from the left.</div>


Relative positioning would result in positioning based on the item before it. Top:0; would move the layer right below the text or whatever comes before the code.

Hopefully now you all have a better understanding of the use of div layers.

Tutorial Comments

Showing latest 10 of 23 comments

@ Design Daddy, Okay I've checked out the website address you posted in your comment but honestly...no offense but the layouts on here for free look better and more professional than the ones you're 'selling'! Come on...

By Butterface89 on Jul 16, 2010 10:03 am

I kinda get it a little more.
:3

By BangKissxx on Jan 5, 2009 6:36 pm

ConFuSinGG... but i kidna get a better idea now. THX :]

By Forsaken-vampiress on Oct 31, 2008 1:22 pm

You can see our div layers here for myspace [url="http://daddydesign.com/ "]http://daddydesign.com/[/ur l]

By daddydesign on Apr 21, 2008 9:21 pm

yes you can make div layers on myspace

By daddydesign on Apr 21, 2008 9:15 pm

This is a very good tutorial. It just gave me the things I needed in a very clear way. Thanks.
I see some guys complain. I wonder if the should go first to not-advanced tutorials. ie: simplyperfect probably needs to go learn img map to make parts of an image to link to different url. VIPStephan says this tutorial is not good because doesn't talk about semantics html, but then again: if you come to a tutorial for advanced users you got to "talk" html, isn't it?
I am happy I find this place.
Saludos!

By elyisus on Mar 7, 2008 12:43 am

heyy im still not too sure on these but thanks for taking the time, im sure it took a while =]
i have a much better idea now though =]
thanks!

By Laura-beth-x on Feb 18, 2008 2:01 pm

okay so im making a div, and i have one picture
this picture has text that says like home, msg, cmt, block and so on..
however, i dont get how to make it so that where that certain part of the picture, i can make that a link, that goes to another page
PLEASE help me!
thanks this helped a lot too! :)

By simplyperfect-layouts on Feb 8, 2008 11:55 pm

i need a code or some sort of attachment that will let me put a backround on my profile when i use this code because it doesn't come with one. it would be awesome if one could be added :]]

By ABnormal on Jan 7, 2008 6:48 pm

alright, so I don't get everything about how to make the DIV layout.
Therefore, I was wondering if you could just send me something to tell me everything about them.

By qlhsunloved on Dec 8, 2007 7:56 pm
View all »

Tutorial Details

Author SteveZz View profile
Submitted on Feb 13, 2006
Page views 118,977
Favorites 120
Comments 23

Tutorial Tags