Solved

Nested Divs in IE and Firefox

Posted on 2007-11-16
7
3,198 Views
Last Modified: 2010-04-21
<div class="ContentBackground" id="ContentBackground">
      <div class="Content" id="Content">
      <div id="Layer1"></div>
      </div>
</div>
Here is my situation...I have a div tag nested inside of a second div tag. ContentBackground has an image in the background. I am trying to center and it works...it works in IE and Firefox...
Now the problem is the nested DIV Content.  I want to center it also over the background image but also want to set the margins so that it sets INSIDE of the background image...
If I get it to work in IE it doesn't in Firefox...Firefox seems to ignore the centering and margins...
Any ideas?
.ContentBackground {
      background-image: url(../images/content.jpg);
      background-repeat: no-repeat;
      height: 413px;
      background-position: center;

}
0
Comment
Question by:cenetadmin
  • 3
  • 2
  • 2
7 Comments
 
LVL 12

Expert Comment

by:oceanbeach
ID: 20302362
Hello cenetadmi,

Do these styles make the divs act the way you need...

.ContentBackground {
      background: url(../images/content.jpg) no-repeat 50% 50%;
      height: 413px;
}
.Content {
margin: 20px;
}

I hope this helps!

oceanbeach
0
 

Author Comment

by:cenetadmin
ID: 20314635
not really...the issue is that the content that i have on TOP of the background image will not go where I want it to...I want it relative to the background image div which should center on the page...(horizontally). I just set the div for the content to aqua so that I could see it...I want it to be about 20 pixels to the right of the background image...but the div is 20 pix relative to the form and not the background div.

My Code:
<div class="ContentBackground" id="ContentBackground">
      <div class="Content" id="Content">
      </div>
</div>

my Content div is:
.Content
{ margin: 20px;
background-color:Aqua;
}
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 20316733
If you're trying to centre the Content div inside the ContentBackground, then set the left and right margin of the Content div to auto. If you don't specify a width for the Content div then it will stretch the full width of the ContentBackground (so centring it won't show any difference.) It will only 'look' centred if the content div is narrower than the ContentBackground div.

Not really clear what you're after. You said you wanted to centre it AND set it to 20px to the right of the background image!! Seems a little contradictory, unless I've misunderstood.

If you need more help, could you show the full code (or point us to a page on the net)
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 12

Accepted Solution

by:
oceanbeach earned 125 total points
ID: 20321178
Hello cenetadmin,

Does it work if you set div.Content to a width that is 40px shorter than the background image width & center it?  Something like...


.ContentBackground {
      background: url(../images/content.jpg) no-repeat 50% 50%;
      height: 413px;
}
.Content {
width: 460px; /* Assumes background image width of 500px minus 40px for margins */
margin: 0 auto;
}

I hope this helps!

-OB
0
 

Author Comment

by:cenetadmin
ID: 20321448
my real issue is this...I need a solution that works in IE and FIrefox...I need a div that has a background image that I can center on the page...then I want to place div's on top of that background div and have them stay relative to the background...and these divs that lay on top of the background div will need to fall within a 'margin' of the background image.
0
 
LVL 43

Expert Comment

by:Chris Stanyon
ID: 20322045
cenetadmin,

Thats exactly what oceanbeach's code does. The .ContentBackground div will stretch the full width of the page. The background image will centre in that DIV. The .Content div is then set to be 40px less than the width of the background image (if you need this div to sit further 'inside' the background, then set it's width to less). The margin:0 auto; then sets the left and right margin of the .Content div to auto, which centres it within the .Contentbackground div
0
 

Author Closing Comment

by:cenetadmin
ID: 31409669
Thanks
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
In this tutorial viewers will learn how to style transparent/translucent elements using alpha transparency in CSS Start with a normal styled element, such as a div.: Define its "background-color" property as "rgba (255, 255, 255, .5): The numbers in…
In this tutorial viewers will learn how to style different bullet points for unordered lists in CSS. Begin with a normal unordered list; the default bullet point is a solid circle: In the CSS, create a defined class of unordered list by typing "ul.S…

792 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question