Trying to align a div in a wrapper

This is a discussion on "Trying to align a div in a wrapper" within the Web Page Design section. This forum, and the thread "Trying to align a div in a wrapper are both part of the Design Your Website category.



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

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old Feb 19th, 2007, 21:07
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Trying to align a div in a wrapper

I am trying to align a div which holds an image but it is not centering.

I have an image i use as a background image which gives the impression the page content is a piece of paper with shadows underneath.

I want to add the content in the actual page and in IE it lines up perfectly but if Firefox it's not. In Firefox the div is aligning to the edge of the background image.

If anyone knows how i can align the content centered in both browsers I would be grateful

The background image is 841px by 5px. I've included a zipped folder with the css file, image and html file if people want to see what is going on.

Here is the CSS for the layout so far
Code: Select all
 
body {
   padding: 0;
   margin:0;
   background-color: #69B7E3;
   width: 100%;
   height: 100%;
   text-align: center;
}
 
.content {
   margin-left: auto;
   margin-right: auto;
   width: 841px;
   height: 100%;
   background-image: url(bg1.gif);
   background-repeat: repeat-y;
}
#title {
   width: 787px; 
   height: 120px; 
   position: relative; 
   top: 2px; 
   left: 0px; 
   z-index: 1;
   background-color: #ffffff; 
   border: none;
}
Attached Files
File Type: zip Copy of test.zip (29.0 KB, 35 views)
Reply With Quote

  #2 (permalink)  
Old Feb 19th, 2007, 21:19
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Trying to align a div in a wrapper

I had the same problem (I probably read the same web page as you did). I eventually made a .gif with the background color filled in, instead of just side/corner/bottom shadow, and they were exactly the same KB in size!

So -- Try doing a graphic with both the shadow and the background. I bet if your background is a solid color, it take no more memory and save a ton of positioning hassles.

I did it in two parts, a shadowed background 1px high and a bottom 7px high, with the corner and bottom shadow.

Have a look
http://www.dhreport.com/test_interactive/waist_hip.php

Last edited by masonbarge; Feb 19th, 2007 at 21:21.
Reply With Quote
  #3 (permalink)  
Old Feb 19th, 2007, 21:35
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Trying to align a div in a wrapper

I have got the background image working OK and it repeats as it should but when i try to add a div it is supposed to center in the screen but it doesn't it.

It takes the left position to the left posistion of the div holding it (i use nested divs)
Reply With Quote
  #4 (permalink)  
Old Feb 20th, 2007, 13:26
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Trying to align a div in a wrapper

I misunderstood, I thought that it was the shadow giving you problems.

FF and IE are both hard with floats and centers in a nested div situation. Actually, I'm surprised: margin: 0 auto has always worked with FF but not IE.

Have you tried adding "text-align: center"? to .content and then text-align:left to the inner boxes?

To tell you the truth, to get cross-browser compliance, I just approximate left margins to internal boxes (especially in float situations) and have alternate style for other browsers if there are differences.
Reply With Quote
  #5 (permalink)  
Old Feb 21st, 2007, 12:17
AdRock's Avatar
SuperMember

SuperMember
Join Date: Jul 2006
Location: Devon, England
Posts: 565
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Trying to align a div in a wrapper

I got it working now

I had to use this

Code: Select all
 
body {
   margin: 0;
   background-color: #69B7E3;
   min-width: 841px;
   text-align: center;
}
 
.content {
   position: relative;
   margin: 0 auto;
   width: 841px;
   height: 100%;
   background-image: url(bg1.gif);
   background-repeat: repeat-y;
   text-align: left;
}
I had to add the min-width property and it lined up properly.

I did have to set the inner div to text-align: left though
Reply With Quote
  #6 (permalink)  
Old Feb 22nd, 2007, 13:20
Junior Member
Join Date: Jan 2007
Location: philly
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Trying to align a div in a wrapper

I wish I had seen this post two weeks ago before I finally figured this out for myself this morning. I did notice that margin 0 auto; worked in FF but not in IE. Will using text align left fix the problem in IE?

http://www.betagammachapter.com/welcome.html
Reply With Quote
  #7 (permalink)  
Old Feb 22nd, 2007, 13:29
karinne's Avatar
SuperMember

SuperMember
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Trying to align a div in a wrapper

margin: 0 auto works in all browsers. However, if you are still supporting IE5.5 then you need to add text-align: center in the parent element.

How to center your site horizontally
<body> can be used to style too!
Reply With Quote
  #8 (permalink)  
Old Feb 22nd, 2007, 16:03
masonbarge's Avatar
Highly Reputable Member
Join Date: Jan 2006
Location: Atlanta GA
Posts: 631
Thanks: 0
Thanked 0 Times in 0 Posts
Re: Trying to align a div in a wrapper

For IE, centering block elements by auto-margins only works starting from version 6 and only when in "standard compliant" mode. I still use text-align for IE 6, just in case of quirk problems.
Reply With Quote
Reply

Tags
center, div, firefox, images

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
Wrapper problem goldy Web Page Design 2 May 30th, 2008 19:11
wrapper not detecting content saltedm8 Web Page Design 4 Apr 6th, 2008 22:31
overhanging an imge in a wrapper div lister110 Website Planning 1 Jan 13th, 2008 18:24
[SOLVED] CSS wrapper affecting body Joolsd186 Web Page Design 7 Dec 31st, 2007 19:11
My navigation breaks my wrapper. tigerslicer Web Page Design 6 Sep 10th, 2007 10:58


All times are GMT. The time now is 20:01.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43