Solved

Nested Divs in IE and Firefox

Posted on 2007-11-16
7
3,199 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

749 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