Div Alignment

This is a discussion on "Div Alignment" within the Web Page Design section. This forum, and the thread "Div Alignment are both part of the Design Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Web Page Design

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Aug 28th, 2006, 04:24
Up'n'Coming Member
Join Date: Aug 2006
Location: California
Age: 20
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Question Div Alignment

Hey, Im working with CSS to code all my div layers, and I am wondering how I can specifically position my divlayers through CSS. I cant figure it out, nor can I find it on any of my "educational" websites for webdesign. Can someone help me out?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Aug 28th, 2006, 05:24
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

These examples will help you out:

float: left;

float: right;

position: absolute
top: 200px;

position: absolute:
left: 90px
bottom: 0;

position: absolute;
right: 50%;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Aug 28th, 2006, 13:06
Up'n'Coming Member
Join Date: Aug 2006
Location: California
Age: 20
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

Wow! Thanks a lot! Thats exactly what I needed!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Aug 28th, 2006, 16:14
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

No problem. Here's a full reference of all the CSS properties:
http://www.w3schools.com/css/css_reference.asp
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Aug 28th, 2006, 16:59
Elite Veteran
Join Date: Aug 2005
Location: That Place
Posts: 2,044
Blog Entries: 1
Thanks: 0
Thanked 37 Times in 37 Posts
Re: Div Alignment

Don't forget position:relative; etc..
__________________

Last Blog Entry: Apps every Mac based web dev should consider (Jul 10th, 2008)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Aug 29th, 2006, 04:40
Up'n'Coming Member
Join Date: Aug 2006
Location: California
Age: 20
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

I just needed to know that float is the command, and a few examples. Thanks for all the help guys! Ill be back later for more help I'm sure :P
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Sep 3rd, 2006, 21:19
Up'n'Coming Member
Join Date: Aug 2006
Location: California
Age: 20
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

Let me bring the thread back to life for a second. Let me make sure what I am doing wrong here, and hopefully Ill understand! This is the Index file right here...

Quote:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="content.css" />
<title>Scoff Skateboarding</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>
<body>
<div class:main>Content Goes here</div>
</body>
</html>
And this is the CSS file Im working with. This is what I am compleatly new to, so let me know what I am doing wrong if I am anywhere!

Quote:
/* CSS Document */

h1
{
color: #0099FF
}

h2
{
}

body
{
background-color:#005fa4;
background-image:url(Backing copy.gif);
background-position:top;
background-repeat:repeat-x;
}

div.main
{
border:2px;
border-color:#000000;
width: 600px;
height: 400px;
position: absolute;
right: 50%;
}
Now, I dont know much about it, but the background propertys are working great in firefox. I dont know if all the propertys will work in other browsers, but so far so good for me...

Its the Div command Im using thats not working. It dosnt look like I am having any control over my Div propertys at all. How can I pull this stuff off?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Sep 3rd, 2006, 21:59
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

Your mistake is in this syntax here:
Code: Select all
 <div class:main>Content Goes here</div>
The correct syntax is:
Code: Select all
class='main'
Remember, class definitions, ie., those defined '.def' can be used many times on a page whereas id definitions, defined '#def' must be unique on a page.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Sep 4th, 2006, 00:54
Up'n'Coming Member
Join Date: Aug 2006
Location: California
Age: 20
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

Heh. Thanks! I shoulda known better.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Sep 4th, 2006, 01:01
Up'n'Coming Member
Join Date: Aug 2006
Location: California
Age: 20
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

Alright I have a new problem. The code that positioned the layer didnt work entirely. I could swap out the colors and stuff, but its not allowing a border to show at all, and its not positioning to the center properly. Wouldnt that right 50% command do that for me?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Sep 4th, 2006, 14:54
Most Reputable Member
Join Date: Apr 2006
Location: Cornwall, UK
Posts: 1,310
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

No. What that is saying is position the element (its right side) 50% of the window width from the right-hand side of the window.

To position something in the centre, you nedd to use the margin: auto; instruction.

You can set various combinations such as margin: auto auto; which will centre top to bottom as well. You can also use fixed measurements for say top to bottom and auto for side to side.

Have a play.

WARNING: IE 6 doesn't do this properly but it is fixed in IE7 we are told!

To get round this, you need to give the div containing the one you wish to centre the attribute definition; text-align: center;

As this has a ripple down effect, you will need to compansate for this by using text-align: left; at the next level in.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Sep 6th, 2006, 00:56
Up'n'Coming Member
Join Date: Aug 2006
Location: California
Age: 20
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

Alright now, I hate to keep coming back to you, but its helping, so if you would still hang in here with me it would be MUCH appreciated.

Your margin:auto worked great, but now I need to pull it down from the top a bit. What should I do about this. I have an idea that I should probably just use the .main div to hold many other divs inside, and use that as a template, but is there a better way?

I also noticed that the way I have my background set up...
Quote:
body
{
background-color:#005fa4;
background-image:url(Backing copy.gif);
background-position:top;
background-repeat:repeat-x;
}
Wont work in firefox properly. It dosnt display the image at all, but the color is everywhere. What can I do about that to?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Sep 6th, 2006, 02:31
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

This is CSS shorthand:

Code: Select all
body {
    background: #005fa4 url("backing_copy.gif") repeat-x 0 20px;
}
  • Never uses spaces in file names.
  • Always put quotes around the filename in CSS.
  • The 0 20px translates to: the background image starts zero pixels from the left and 20 pixels from the top.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Sep 6th, 2006, 03:55
Up'n'Coming Member
Join Date: Aug 2006
Location: California
Age: 20
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

That works great! I can now write freehand. Didnt know about it. Dreamweaver also supports it in its auto writing stuff, so that helps a lot!

How does that "0 20px" thing work? Does it have a special order to it, or am I not seeing it?

Ah! Im also answering a few of my own questions myself. I think I am getting the hang of this! So far so good

Last edited by escaflowne11; Sep 6th, 2006 at 04:13.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Sep 6th, 2006, 09:46
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

The order is left top. If you used 20px 50%, it would put the background image 20 pixels from the left and vertically centered.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old Sep 6th, 2006, 09:50
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

Oh, most sites use top left as a designation (top, right, bottom and left are also valid positons), but this is wrong it should be left top. I've always found it easier to use pixels and percentages though, plus it reminds the coder of the proper order. Right bottom would be 100% 100%, whereas left top would be 0 0, 0px 0px or 0% 0%.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #17  
Old Sep 6th, 2006, 10:12
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

first number is horizontal, second is vertical. Usually you will designate it, because you can push it from the other direction, e.g. position: relative; bottom: 10px; right 9px;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #18  
Old Sep 8th, 2006, 00:33
Up'n'Coming Member
Join Date: Aug 2006
Location: California
Age: 20
Posts: 58
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Div Alignment

Here is the code I have right now, and now for the problems I ran acrossed yet again. Thanks for getting me so far in this, I hope I can repay the favor later on!

Quote:
/* CSS Document */

h1
{
color: #0099FF
}

h2
{
}

body
{
background: #005fa4 url("backing.gif") repeat-x;
}

div.container
{
margin: auto;
height: 600px;
width: 600px;
}

div.header
{
margin: auto;
height: 120px;
width: 590px;
}

div.nav
{
border-width: 2px;
border-color: #000000;
border-style: solid;
margin: auto;
heigth: 40px;
width: 590px;
background-color: #FFFFFF;
}

div.body
{
border-width: 2px;
border-color: #000000;
border-style: solid;
margin: auto;
heigth: 400px;
width: 590px;
background-color: #FFFFFF;
}
Quote:
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="content.css" />
<title>Scoff Skateboarding</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

</head>
<body>
<div class='container'>
<div class='header'></div>


<div class='nav'></div>
<div class='body'></div>
<div class='nav'></div>


</div>
</body>
</html>
Now the problems I ran acrossed was that now that I have multiple div layers in play, they dont want to conform to the dimensions I am giving them. I cant get the height to work for the 'nav's, and the 'body'. I also cant get the borders to work properly, along with the background color... I had them at one time, but now they wont show at all. And thats in firefox. Explorer includes the border, with the background color, but wont use the dimensions. Any thoughts on this problem?

If you want to see the style I am aiming for check out the old, trashy site. http://www.scoffshop.com

Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Tags
div, alignment

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
DIV alignment help